diff --git a/CHANGELOG.md b/CHANGELOG.md index a79c34ba..192933f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -107,6 +107,8 @@ All notable changes to this project will be documented in this file. It uses the * Fixed a use-after-free of a foreign scan's batch memory context on rescan that could corrupt memory and hang ([#296]). * Fixed subsecond precision lost inserting timestamps over HTTP ([#300]). +* Fixed loss of subsecond precision in `to_timestamp(float8)` by mapping it + to ClickHouse's microsecond-precision `toDateTime64()` function ([#338]). * Fixed `date_part('dow', ...)` and `EXTRACT(DOW FROM ...)` pushdown to use PostgreSQL's Sunday (`0`) through Saturday (`6`) numbering, rather than ClickHouse's default Monday through Sunday scheme. Thanks to Minh Vu for @@ -211,6 +213,8 @@ All notable changes to this project will be documented in this file. It uses the "ClickHouse/pg_clickhouse#335 Reject JSON paths containing NULL elements" [#336]: https://github.com/ClickHouse/pg_clickhouse/pull/336 "ClickHouse/pg_clickhouse#336 Preserve array_length semantics" + [#338]: https://github.com/ClickHouse/pg_clickhouse/pull/338 + "ClickHouse/pg_clickhouse#338 Preserve fractional seconds in to_timestamp()" ## [v0.3.2] — 2026-06-16 diff --git a/doc/pg_clickhouse.md b/doc/pg_clickhouse.md index 28ee6483..a2020d97 100644 --- a/doc/pg_clickhouse.md +++ b/doc/pg_clickhouse.md @@ -1272,7 +1272,8 @@ equivalents as follows: * `jsonb_extract_path_text`: [sub-column syntax](https://clickhouse.com/docs/sql-reference/data-types/newjson#reading-json-paths-as-sub-columns) * `jsonb_extract_path`: [toJSONString](https://clickhouse.com/docs/sql-reference/functions/json-functions#toJSONString) + [sub-column syntax](https://clickhouse.com/docs/sql-reference/data-types/newjson#reading-json-paths-as-sub-columns) * `bit_count(bytea)`: [bitCount](https://clickhouse.com/docs/sql-reference/functions/bit-functions#bitcount) -* `to_timestamp(float8)`: [fromUnixTimestamp](https://clickhouse.com/docs/sql-reference/functions/date-time-functions#fromUnixTimestamp) +* `to_timestamp(float8)`: [toDateTime64](https://clickhouse.com/docs/sql-reference/functions/type-conversion-functions#todatetime64) + with microsecond precision and the `UTC` timezone. * `to_char(timestamp[tz], fmt)`: [formatDateTime](https://clickhouse.com/docs/sql-reference/functions/date-time-functions#formatDateTime) when `fmt` is a string constant whose every keyword has a faithful ClickHouse equivalent. See [to_char()](#to_char) under Compatibility diff --git a/src/custom_types.c b/src/custom_types.c index ea6670dc..f4e21b8b 100644 --- a/src/custom_types.c +++ b/src/custom_types.c @@ -594,11 +594,9 @@ lookup_builtin_func(Oid funcid, builtin_func_def* def) { return true; /* CH lacks "power", maps to pow */ case F_TO_TIMESTAMP_FLOAT8: - def->ch_name = "fromUnixTimestamp(toInt64"; - def->paren_count = 2; + def->cf_type = CF_TO_TIMESTAMP; + def->ch_name = "\1"; return true; - /* ClickHouse doesn't work with subsecond precision */ - /* timestamps. */ case F_TO_CHAR_TIMESTAMP_TEXT: case F_TO_CHAR_TIMESTAMPTZ_TEXT: def->cf_type = CF_TO_CHAR; diff --git a/src/deparse.c b/src/deparse.c index 8fadef8f..8ea3c686 100644 --- a/src/deparse.c +++ b/src/deparse.c @@ -4406,6 +4406,12 @@ deparseFuncExpr(FuncExpr* node, deparse_expr_cxt* context) { appendStringInfo(buf, "nowInBlock64(6, %s)", QUOTED_TZ); return; } + case CF_TO_TIMESTAMP: { + appendStringInfoString(buf, "toDateTime64("); + deparseExpr((Expr*)linitial(node->args), context); + appendStringInfoString(buf, ", 6, 'UTC')"); + return; + } case CF_DATE_TRUNC: { Const* arg = (Const*)linitial(node->args); char* trunctype = TextDatumGetCString(arg->constvalue); diff --git a/src/include/fdw.h b/src/include/fdw.h index e5e4669a..21818fdd 100644 --- a/src/include/fdw.h +++ b/src/include/fdw.h @@ -396,6 +396,7 @@ typedef enum { CF_CURRENT_DATABASE, /* CURRENT_DATABASE → string literal */ CF_CURRENT_SCHEMA, /* CF_CURRENT_SCHEMA → string literal */ CF_CLOCK_TIMESTAMP, /* clock_timestamp → nowInBlock64(6, $TZ) */ + CF_TO_TIMESTAMP, /* to_timestamp → toDateTime64($arg, 6, 'UTC') */ CF_ARRAY_LENGTH, /* array_length(array, 1) → nullIf(length(), 0) */ CF_ARRAY_POSITION, /* array_position → nullIf(indexOf(), 0) */ CF_ARRAY_PREPEND, /* array_prepend → arrayPushFront, swap args */ diff --git a/test/expected/functions.out b/test/expected/functions.out index 61e1d39c..94f3f868 100644 --- a/test/expected/functions.out +++ b/test/expected/functions.out @@ -1640,7 +1640,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(i64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(i64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(i64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(0); @@ -1654,7 +1654,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(f64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(f64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(f64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(0); @@ -1668,7 +1668,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(i64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(i64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(i64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(2042323443); @@ -1678,14 +1678,19 @@ SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(2042323443); (1 row) EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443); - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------- Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(f64)) = '2034-09-20 00:04:03')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(f64, 6, 'UTC') = '2034-09-20 00:04:03')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443); + i64 | f64 +-----+----- +(0 rows) + +SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443.232); i64 | f64 ------------+---------------- 2042323443 | 2042323443.232 diff --git a/test/expected/functions_0.out b/test/expected/functions_0.out index 05f94594..e94e42ba 100644 --- a/test/expected/functions_0.out +++ b/test/expected/functions_0.out @@ -1640,7 +1640,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(i64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(i64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(i64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(0); @@ -1654,7 +1654,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(f64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(f64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(f64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(0); @@ -1668,7 +1668,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(i64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(i64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(i64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(2042323443); @@ -1678,14 +1678,19 @@ SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(2042323443); (1 row) EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443); - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------- Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(f64)) = '2034-09-20 00:04:03')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(f64, 6, 'UTC') = '2034-09-20 00:04:03')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443); + i64 | f64 +-----+----- +(0 rows) + +SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443.232); i64 | f64 ------------+---------------- 2042323443 | 2042323443.232 diff --git a/test/expected/functions_1.out b/test/expected/functions_1.out index 733a6474..aac41e84 100644 --- a/test/expected/functions_1.out +++ b/test/expected/functions_1.out @@ -1640,7 +1640,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(i64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(i64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(i64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(0); @@ -1654,7 +1654,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(f64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(f64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(f64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(0); @@ -1668,7 +1668,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(i64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(i64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(i64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(2042323443); @@ -1678,14 +1678,19 @@ SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(2042323443); (1 row) EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443); - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------- Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(f64)) = '2034-09-20 00:04:03')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(f64, 6, 'UTC') = '2034-09-20 00:04:03')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443); + i64 | f64 +-----+----- +(0 rows) + +SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443.232); i64 | f64 ------------+---------------- 2042323443 | 2042323443.232 diff --git a/test/expected/functions_2.out b/test/expected/functions_2.out index 89433525..2ca19546 100644 --- a/test/expected/functions_2.out +++ b/test/expected/functions_2.out @@ -1640,7 +1640,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(i64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(i64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(i64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(0); @@ -1654,7 +1654,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(f64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(f64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(f64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(0); @@ -1668,7 +1668,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(i64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(i64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(i64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(2042323443); @@ -1678,14 +1678,19 @@ SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(2042323443); (1 row) EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443); - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------- Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(f64)) = '2034-09-20 00:04:03')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(f64, 6, 'UTC') = '2034-09-20 00:04:03')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443); + i64 | f64 +-----+----- +(0 rows) + +SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443.232); i64 | f64 ------------+---------------- 2042323443 | 2042323443.232 diff --git a/test/expected/functions_3.out b/test/expected/functions_3.out index 8a0a802c..99d06a8e 100644 --- a/test/expected/functions_3.out +++ b/test/expected/functions_3.out @@ -1640,7 +1640,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(i64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(i64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(i64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(0); @@ -1654,7 +1654,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(f64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(f64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(f64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(0); @@ -1668,7 +1668,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(i64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(i64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(i64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(2042323443); @@ -1678,14 +1678,19 @@ SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(2042323443); (1 row) EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443); - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------- Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(f64)) = '2034-09-20 00:04:03')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(f64, 6, 'UTC') = '2034-09-20 00:04:03')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443); + i64 | f64 +-----+----- +(0 rows) + +SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443.232); i64 | f64 ------------+---------------- 2042323443 | 2042323443.232 diff --git a/test/expected/functions_4.out b/test/expected/functions_4.out index 15b9f691..f8d3a79d 100644 --- a/test/expected/functions_4.out +++ b/test/expected/functions_4.out @@ -1636,7 +1636,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(i64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(i64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(i64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(0); @@ -1650,7 +1650,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(f64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(f64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(f64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(0); @@ -1664,7 +1664,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(i64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(i64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(i64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(2042323443); @@ -1674,14 +1674,19 @@ SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(2042323443); (1 row) EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443); - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------- Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(f64)) = '2034-09-20 00:04:03')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(f64, 6, 'UTC') = '2034-09-20 00:04:03')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443); + i64 | f64 +-----+----- +(0 rows) + +SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443.232); i64 | f64 ------------+---------------- 2042323443 | 2042323443.232 diff --git a/test/expected/functions_5.out b/test/expected/functions_5.out index 283a2d82..870109c9 100644 --- a/test/expected/functions_5.out +++ b/test/expected/functions_5.out @@ -1636,7 +1636,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(i64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(i64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(i64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(0); @@ -1650,7 +1650,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(f64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(f64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(f64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(0); @@ -1664,7 +1664,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(i64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(i64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(i64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(2042323443); @@ -1674,14 +1674,19 @@ SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(2042323443); (1 row) EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443); - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------- Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(f64)) = '2034-09-20 00:04:03')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(f64, 6, 'UTC') = '2034-09-20 00:04:03')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443); + i64 | f64 +-----+----- +(0 rows) + +SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443.232); i64 | f64 ------------+---------------- 2042323443 | 2042323443.232 diff --git a/test/expected/functions_6.out b/test/expected/functions_6.out index a3095973..df92a7b7 100644 --- a/test/expected/functions_6.out +++ b/test/expected/functions_6.out @@ -1636,7 +1636,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(i64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(i64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(i64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(0); @@ -1650,7 +1650,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(f64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(f64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(f64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(0); @@ -1664,7 +1664,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(i64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(i64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(i64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(2042323443); @@ -1674,14 +1674,19 @@ SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(2042323443); (1 row) EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443); - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------- Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(f64)) = '2034-09-20 00:04:03')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(f64, 6, 'UTC') = '2034-09-20 00:04:03')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443); + i64 | f64 +-----+----- +(0 rows) + +SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443.232); i64 | f64 ------------+---------------- 2042323443 | 2042323443.232 diff --git a/test/expected/functions_7.out b/test/expected/functions_7.out index d4ab979b..dce96314 100644 --- a/test/expected/functions_7.out +++ b/test/expected/functions_7.out @@ -1636,7 +1636,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(i64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(i64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(i64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(0); @@ -1650,7 +1650,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(f64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(f64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(f64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(0); @@ -1664,7 +1664,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(i64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(i64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(i64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(2042323443); @@ -1674,14 +1674,19 @@ SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(2042323443); (1 row) EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443); - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------- Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(f64)) = '2034-09-20 00:04:03')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(f64, 6, 'UTC') = '2034-09-20 00:04:03')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443); + i64 | f64 +-----+----- +(0 rows) + +SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443.232); i64 | f64 ------------+---------------- 2042323443 | 2042323443.232 diff --git a/test/expected/functions_8.out b/test/expected/functions_8.out index 82b41789..87a1ed71 100644 --- a/test/expected/functions_8.out +++ b/test/expected/functions_8.out @@ -1636,7 +1636,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(i64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(i64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(i64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(0); @@ -1650,7 +1650,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(f64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(f64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(f64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(0); @@ -1664,7 +1664,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(i64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(i64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(i64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(2042323443); @@ -1674,14 +1674,19 @@ SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(2042323443); (1 row) EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443); - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------- Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(f64)) = '2034-09-20 00:04:03')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(f64, 6, 'UTC') = '2034-09-20 00:04:03')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443); + i64 | f64 +-----+----- +(0 rows) + +SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443.232); i64 | f64 ------------+---------------- 2042323443 | 2042323443.232 diff --git a/test/expected/functions_9.out b/test/expected/functions_9.out index b2de027e..716b34c2 100644 --- a/test/expected/functions_9.out +++ b/test/expected/functions_9.out @@ -1636,7 +1636,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(i64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(i64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(i64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(0); @@ -1650,7 +1650,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(f64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(f64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(f64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(0); @@ -1664,7 +1664,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(i64) = to_times ------------------------------------------------------------------------------------------------------------------------ Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(i64)) = '1970-01-01 00:00:00')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(i64, 6, 'UTC') = '1970-01-01 00:00:00')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(2042323443); @@ -1674,14 +1674,19 @@ SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(2042323443); (1 row) EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443); - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------- Foreign Scan on public.t6 Output: i64, f64 - Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((fromUnixTimestamp(toInt64(f64)) = '2034-09-20 00:04:03')) + Remote SQL: SELECT i64, f64 FROM functions_test.t6 WHERE ((toDateTime64(f64, 6, 'UTC') = '2034-09-20 00:04:03')) (3 rows) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443); + i64 | f64 +-----+----- +(0 rows) + +SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443.232); i64 | f64 ------------+---------------- 2042323443 | 2042323443.232 diff --git a/test/sql/functions.sql b/test/sql/functions.sql index 74b467b7..d22238eb 100644 --- a/test/sql/functions.sql +++ b/test/sql/functions.sql @@ -371,6 +371,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(i64) = to_times SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(2042323443); EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443); SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443); +SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(2042323443.232); -- Check current_*-type functions. EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE c < NOW();