Skip to content
This repository was archived by the owner on Dec 29, 2025. It is now read-only.
This repository was archived by the owner on Dec 29, 2025. It is now read-only.

PostgreSQL EXTRACT Function based on Clickhouse table doesn't work in ORDER BY clause #98

@mixavich

Description

@mixavich

A simple query
SELECT "InsertionDate" from "AdvertisingCab" order by extract(YEAR from "InsertionDate"), extract (MONTH from "InsertionDate");
, where AdvertisingCab is a PostgreSQL view linked to a similar Clickhouse table, falls with the following error:

ERROR: clickhouse_fdw:Code: 43. DB::Exception: Illegal type DateTime('UTC') of argument of function extract: While processing extract('year', insertion_date) ASC, extract('month', insertion_date) ASC. (ILLEGAL_TYPE_OF_ARGUMENT)
QUERY:SELECT "insertion_date" FROM "test".advertising_cabinet ORDER BY extract('year', "insertion_date") ASC, extract('month', "insertion_date") ASC

In other words, clickhouse_fdw translates the extract functions in the order by clause incorrectly.

At the same time the query
SELECT extract(YEAR from "InsertionDate"), extract (MONTH from "InsertionDate") from "AdvertisingCab"
translates into

QUERY PLAN

Foreign Scan on public.advertising_cabinet (cost=0.00..0.00 rows=0 width=64)
Output: EXTRACT(year FROM advertising_cabinet."insertion_date"), EXTRACT(month FROM advertising_cabinet."insertion_date")
Remote SQL: SELECT "insertion_date" FROM "test".advertising_cabinet
(3 rows)

and works perfectly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions