Skip to content

Commit

Permalink
Add NOW() to PostgreSQL (#3403)
Browse files Browse the repository at this point in the history
Co-authored-by: hfhbd <hfhbd@users.noreply.github.com>
  • Loading branch information
2 people authored and AlecKazakova committed Aug 5, 2022
1 parent e5643f6 commit e60c265
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
Expand Up @@ -86,6 +86,7 @@ class PostgreSqlTypeResolver(private val parentResolver: TypeResolver) : TypeRes
"max" -> encapsulatingType(exprList, SMALL_INT, PostgreSqlType.INTEGER, INTEGER, BIG_INT, REAL, TEXT, BLOB).asNullable()
"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)
else -> null
}

Expand Down
@@ -0,0 +1,5 @@
CREATE TABLE foo (
bar TIMESTAMPTZ NOT NULL
);

SELECT NOW() AS now, date_trunc('hour', bar) AS d FROM foo;
Expand Up @@ -12,3 +12,6 @@ RETURNING *;

selectDateTrunc:
SELECT date_trunc('hour', timestamp), date_trunc('hour', timestamp_with_timezone) FROM dates;

selectNow:
SELECT NOW();
Expand Up @@ -126,6 +126,12 @@ class PostgreSqlTest {
}
}

@Test fun now() {
val now = database.datesQueries.selectNow().executeAsOne()
assertThat(now).isNotNull()
assertThat(now).isGreaterThan(OffsetDateTime.MIN)
}

@Test fun successfulOptimisticLock() {
with(database.withLockQueries) {
val row = insertText("sup").executeAsOne()
Expand Down

0 comments on commit e60c265

Please sign in to comment.