Skip to content
This repository was archived by the owner on Dec 29, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/adjust.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ CustomObjectDef *chfdw_check_for_custom_function(Oid funcid)
case 868: // strpos
case F_BTRIM:
case F_BTRIM1:
case F_TO_TIMESTAMP:
special_builtin = true;
break;
default:
Expand Down Expand Up @@ -153,6 +154,12 @@ CustomObjectDef *chfdw_check_for_custom_function(Oid funcid)
strcpy(entry->custom_name, "position");
break;
}
case F_TO_TIMESTAMP:
{
entry->cf_type = CF_TO_TIMESTAMP;
entry->custom_name[0] = '\1';
break;
}
}

if (special_builtin)
Expand Down
12 changes: 11 additions & 1 deletion src/deparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -2359,6 +2359,16 @@ deparseFuncExpr(FuncExpr *node, deparse_expr_cxt *context)
* Normal function: display as proname(args).
*/
cdef = appendFunctionName(node->funcid, context);

if (cdef && cdef->cf_type == CF_TO_TIMESTAMP)
{
appendStringInfoString(buf, "parseDateTimeBestEffortOrNull");
appendStringInfoChar(buf, '(');
deparseExpr(list_nth(node->args, 0), context);
appendStringInfoChar(buf, ')');
return;
}

if (cdef && cdef->cf_type == CF_DATE_TRUNC)
{
Const *arg = (Const *) linitial(node->args);
Expand Down Expand Up @@ -2409,7 +2419,7 @@ deparseFuncExpr(FuncExpr *node, deparse_expr_cxt *context)
{
appendStringInfoString(buf, "(toDateTime64(");
deparseExpr(list_nth(node->args, 1), context);
appendStringInfoString(buf, ", 1))");
appendStringInfoString(buf, ", 1, 'UTC'))");
}
else
{
Expand Down
1 change: 1 addition & 0 deletions src/include/clickhousedb_fdw.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ typedef enum {
CF_DATE_PART, /* date_part function */
CF_TIMESTAMPTZ_PL_INTERVAL, /* timestamptz + interval */
CF_TIMEZONE, /* timezone */
CF_TO_TIMESTAMP,
CF_COUNTRY_TYPE,
CF_AJTIME_PL_INTERVAL,
CF_AJTIME_MI_INTERVAL,
Expand Down
16 changes: 16 additions & 0 deletions tests/expected/functions.out
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,22 @@ SELECT uniq_exact(a) FILTER(WHERE b>1) FROM t1;
1
(1 row)

EXPLAIN (VERBOSE, COSTS OFF) SELECT c as d1 FROM t1 WHERE c >= to_timestamp('2019-01-01 00:00:00.000000', 'YYYY-MM-DD HH24:MI:SS.US') GROUP BY d1 ORDER BY d1;
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Foreign Scan
Output: c
Relations: Aggregate on (t1)
Remote SQL: SELECT c FROM regression.t1 WHERE ((c >= parseDateTimeBestEffortOrNull('2019-01-01 00:00:00.000000'))) GROUP BY c ORDER BY c ASC
(4 rows)

SELECT c as d1 FROM t1 WHERE c >= to_timestamp('2019-01-01 00:00:00.000000', 'YYYY-MM-DD HH24:MI:SS.US') GROUP BY d1 ORDER BY d1;
d1
------------------------
2019-01-01 10:00:00
2019-01-02 10:00:00
(2 rows)

EXPLAIN (VERBOSE, COSTS OFF) SELECT date_trunc('dAy', c at time zone 'UTC') as d1 FROM t1 GROUP BY d1 ORDER BY d1;
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions tests/sql/functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ SELECT uniq_exact(a) FROM t1;
EXPLAIN (VERBOSE, COSTS OFF) SELECT uniq_exact(a) FILTER(WHERE b>1) FROM t1;
SELECT uniq_exact(a) FILTER(WHERE b>1) FROM t1;

EXPLAIN (VERBOSE, COSTS OFF) SELECT c as d1 FROM t1 WHERE c >= to_timestamp('2019-01-01 00:00:00.000000', 'YYYY-MM-DD HH24:MI:SS.US') GROUP BY d1 ORDER BY d1;
SELECT c as d1 FROM t1 WHERE c >= to_timestamp('2019-01-01 00:00:00.000000', 'YYYY-MM-DD HH24:MI:SS.US') GROUP BY d1 ORDER BY d1;

EXPLAIN (VERBOSE, COSTS OFF) SELECT date_trunc('dAy', c at time zone 'UTC') as d1 FROM t1 GROUP BY d1 ORDER BY d1;
SELECT date_trunc('day', c at time zone 'UTC') as d1 FROM t1 GROUP BY d1 ORDER BY d1;

Expand Down