From 8bb55172e02e46a949e354cbc6e7125e59859122 Mon Sep 17 00:00:00 2001 From: mertmit Date: Wed, 18 Oct 2023 07:30:02 +0000 Subject: [PATCH] feat: support for pg identity column --- .../nocodb/src/db/sql-client/lib/pg/PgClient.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/nocodb/src/db/sql-client/lib/pg/PgClient.ts b/packages/nocodb/src/db/sql-client/lib/pg/PgClient.ts index 10a8e3da1b..8d2d545196 100644 --- a/packages/nocodb/src/db/sql-client/lib/pg/PgClient.ts +++ b/packages/nocodb/src/db/sql-client/lib/pg/PgClient.ts @@ -781,6 +781,14 @@ class PGClient extends KnexClient { const result = new Result(); log.api(`${_func}:args:`, args); try { + const versionQuery = await this.sqlClient.raw('SELECT version()'); + + const version = versionQuery.rows[0]?.version + ?.split(' ')?.[1] + ?.split('.')?.[0]; + + const identitySelector = +version >= 10 ? 'c.is_identity as ii,' : ''; + args.databaseName = this.connectionConfig.connection.database; const response = await this.sqlClient.raw( `select @@ -800,6 +808,7 @@ class PGClient extends KnexClient { -- c.collation_name as clnn, pk.ordinal_position as pk_ordinal_position, pk.constraint_name as pk_constraint_name, c.udt_name, + ${identitySelector} (SELECT count(*) FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc1 @@ -893,6 +902,13 @@ class PGClient extends KnexClient { column.dtxp = response.rows[i].enum_values; } + // handle identity column + if (+version >= 10) { + if (response.rows[i].ii === 'YES') { + column.ai = true; + } + } + columns.push(column); }