Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support and test for gen_random_uuid() #3855

Merged
merged 6 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class PostgreSqlTypeResolver(private val parentResolver: TypeResolver) : TypeRes
"min" -> encapsulatingType(exprList, BLOB, TEXT, SMALL_INT, INTEGER, PostgreSqlType.INTEGER, BIG_INT, REAL).asNullable()
"date_trunc" -> encapsulatingType(exprList, TIMESTAMP_TIMEZONE, TIMESTAMP)
"now" -> IntermediateType(TIMESTAMP_TIMEZONE)
"gen_random_uuid" -> IntermediateType(PostgreSqlType.UUID)
else -> null
}

Expand Down
7 changes: 7 additions & 0 deletions dialects/postgresql/src/test/fixtures_postgresql/uuids/Test.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE uuid_test (
pk uuid
);

SELECT gen_random_uuid(), pk FROM uuid_test;

INSERT INTO uuid_test(pk) SELECT gen_random_uuid();
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE uuids(
key uuid NOT NULL
);

insertUuid:
INSERT INTO uuids (key) VALUES (:key);

randomUuid:
SELECT gen_random_uuid();
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import java.time.LocalDateTime
import java.time.LocalTime
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util.UUID

class PostgreSqlTest {
val conn = DriverManager.getConnection("jdbc:tc:postgresql:9.6.8:///my_db")
val conn = DriverManager.getConnection("jdbc:tc:postgresql:latest:///my_db")
val driver = object : JdbcDriver() {
override fun getConnection() = conn
override fun closeConnection(connection: Connection) = Unit
Expand Down Expand Up @@ -186,4 +187,9 @@ class PostgreSqlTest {
insertRef(RefTable(RefTable.Id(10), id))
}
}

@Test fun genRandomUuid() {
val uuid: UUID = database.uuidsQueries.randomUuid().executeAsOne()
assertThat(uuid).isNotNull()
}
}