Skip to content

Commit

Permalink
docs: show create table for postgres_foreign_table (#1391)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunng87 authored Dec 20, 2024
1 parent 2e5e230 commit 6ad8478
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
15 changes: 14 additions & 1 deletion docs/user-guide/protocols/postgresql.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ CREATE TABLE app_logs (
) with('append_mode'='true');
```

You will need to define them like this in Postgres.
The foreign table DDL is like this. You need to run them in Postgres to create
these tables;

```sql
CREATE FOREIGN TABLE ft_grpc_latencies (
Expand All @@ -150,6 +151,18 @@ SERVER greptimedb
OPTIONS (table_name 'app_logs');
```

To help you to generate statements in Postgres, we enhanced `SHOW CREATE TABLE`
in GreptimeDB to dump the Postgres DDL for you. For example:

```sql
SHOW CREATE TABLE grpc_latencies FOR postgres_foreign_table;
```

Note that you will need to replace server name `greptimedb` with the name you
defined in `CREATE SERVER` statement.

### Run Queries

You can now send query from Postgres. It's also possible to use functions that
are available in both Postgres and GreptimeDB, like `date_trunc`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ SERVER greptimedb
OPTIONS (table_name 'app_logs');
```

为了帮助用户生成这些语句,我们在 GreptimeDB 里增强了 `SHOW CREATE TABLE` 来直接
输出可执行的语句。

```sql
SHOW CREATE TABLE grpc_latencies FOR postgres_foreign_table;
```

注意在输出的语句中你需要把服务器名 `greptimedb` 替换为之前在 `CREATE SERVER` 语句
里使用的名字。

### 执行查询

至此你可以通过 Postgres 发起查询。并且可以使用一些同时存在在 GreptimeDB 和
Postgres 上的函数,如 `date_trunc` 等。

Expand Down

0 comments on commit 6ad8478

Please sign in to comment.