Documentation Index
Fetch the complete documentation index at: https://private-7c7dfe99-page-updates.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
postgresql Table Function
AllowsSELECT and INSERT queries to be performed on data that is stored on a remote PostgreSQL server.
Syntax
Arguments
| Argument | Description |
|---|---|
host:port | PostgreSQL server address. |
database | Remote database name. |
table | Remote table name. |
user | PostgreSQL user. |
password | User password. |
schema | Non-default table schema. Optional. |
on_conflict | Conflict resolution strategy. Example: ON CONFLICT DO NOTHING. Optional. |
host and port should be specified separately. This approach is recommended for production environment.
Returned value
A table object with the same columns as the original PostgreSQL table.In the
INSERT query to distinguish table function postgresql(...) from table name with column names list you must use keywords FUNCTION or TABLE FUNCTION. See examples below.Implementation Details
SELECT queries on PostgreSQL side run as COPY (SELECT ...) TO STDOUT inside read-only PostgreSQL transaction with commit after each SELECT query.
Simple WHERE clauses such as =, !=, >, >=, <, <=, and IN are executed on the PostgreSQL server.
All joins, aggregations, sorting, IN [ array ] conditions and the LIMIT sampling constraint are executed in ClickHouse only after the query to PostgreSQL finishes.
INSERT queries on PostgreSQL side run as COPY "table_name" (field1, field2, ... fieldN) FROM STDIN inside PostgreSQL transaction with auto-commit after each INSERT statement.
PostgreSQL Array types converts into ClickHouse arrays.
Be careful, in PostgreSQL an array data type column like Integer[] may contain arrays of different dimensions in different rows, but in ClickHouse it is only allowed to have multidimensional arrays of the same dimension in all rows.
|. For example:
0.
Examples
Table in PostgreSQL:Related
Replicating or migrating Postgres data with with PeerDB
In addition to table functions, you can always use PeerDB by ClickHouse to set up a continuous data pipeline from Postgres to ClickHouse. PeerDB is a tool designed specifically to replicate data from Postgres to ClickHouse using change data capture (CDC).