ClickHouse/docs/en/engines/table-engines/integrations/postgresql.md
olgarev a4bd6939c9
Apply suggestions from code review
Co-authored-by: Anna <42538400+adevyatova@users.noreply.github.com>
2021-03-09 23:46:47 +03:00

2.0 KiB

toc_priority toc_title
11 PostgreSQL

#PostgreSQL {#postgresql}

The PostgreSQL engine allows to perform SELECT and INSERT queries on data that is stored on a remote PostgreSQL server.

Creating a Table

CREATE TABLE [IF NOT EXISTS] [db.]table_name [ON CLUSTER cluster]
(
    name1 [type1] [DEFAULT|MATERIALIZED|ALIAS expr1] [TTL expr1],
    name2 [type2] [DEFAULT|MATERIALIZED|ALIAS expr2] [TTL expr2],
    ...
) ENGINE = PostgreSQL('host:port', 'database', 'table', 'user', 'password');

See a detailed description of the CREATE TABLE query.

Engine Parameters

  • host:port — MySQL server address.

  • database — Remote database name.

  • table — Remote table name.

  • user — MySQL user.

  • password — User password.

Usage Example

Consider the table in ClickHouse, retrieving data from the PostgreSQL table:

CREATE TABLE test_table
(
    `int_id` Int32,
    'value' Int32
)
ENGINE = PostgreSQL('localhost:5432', 'test_database', 'test_table', 'postgres', 'mysecretpassword');
SELECT * FROM test_database.test_table;
┌─int_id─┬─value─┐
│      1 │     2 │
└────────┴───────┘

Inserting data from ClickHouse into the PosegreSQL table:

INSERT INTO test_database.test_table VALUES (3,4);
SELECT * FROM test_database.test_table;
┌─int_id─┬─value─┐
│      1 │     2 │
│      3 │     4 │
└────────┴───────┘

See Also

Original article