返回集成

PostgreSQL

核心

注意: 您可能需要授权 ClickHouse Cloud 访问您的 PostgreSQL 实例。完整的 ClickHouse Cloud 出站 IP 地址列表请见此处

使用 PostgreSQL 表函数

您可以使用 PostgreSQL 表函数查询远程 PostgreSQL 表。

SELECT * FROM PostgreSQL('<postgres_host>:<port>', '<schema>', '<database>', '<user>', '<password>');

创建 PostgreSQL 表,无需提供模式

您还可以使用 ClickHouse Cloud 服务中的 PostgreSQL 表引擎创建表,无需使用 CREATE TABLE AS 语法指定模式。当 ClickHouse 在本地创建表时,PostgreSQL 中的类型将映射到等效的 ClickHouse 类型。

CREATE TABLE mycountries AS PostgreSQL('<postgres_host>:5432', '', 'countries', 'postgres', '<password>');

注意: 您可以使用设置 external_table_functions_use_nulls = 0 来确保 Null 值表示为其默认值(而不是 Null)。如果设置为 1(默认值),ClickHouse 将为每列创建 Nullable 变体。

创建具有自定义模式的 PostgreSQL 表

您还可以决定在您的 ClickHouse 服务中使用 PostgreSQL 表引擎创建表,方法是指定自定义模式。

CREATE TABLE default.postgresql_table
(
    `float_nullable` Nullable(Float32),
    `str` String,
    `int_id` Int32
)
ENGINE = PostgreSQL('<postgres_host>:<port>', '<schema>', '<database>', '<user>', '<password>');

其他集成

开始使用 ClickHouse 免费

我们将为您提供 30 天试用期和 300 美元信用额度,供您自行支配。
©2025ClickHouse, Inc. 总部位于加利福尼亚州湾区和荷兰阿姆斯特丹。