Browse Source

Merge pull request #6714 from nocodb/nc-fix/2561-pg

feat: support for pg identity column
pull/6727/head
mertmit 1 year ago committed by GitHub
parent
commit
26f59a6d11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      packages/nocodb/src/db/sql-client/lib/pg/PgClient.ts

20
packages/nocodb/src/db/sql-client/lib/pg/PgClient.ts

@ -781,6 +781,18 @@ class PGClient extends KnexClient {
const result = new Result(); const result = new Result();
log.api(`${_func}:args:`, args); log.api(`${_func}:args:`, args);
try { try {
const versionQuery = await this.sqlClient.raw('SELECT version()');
// Example output of `SELECT version()`
// PostgreSQL 14.4 (Debian 14.4-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
const majorVersion = versionQuery.rows[0]?.version
?.split(' ')?.[1]
?.split('.')?.[0];
// PostgreSQL 10 and above supports identity columns
const identitySelector =
+majorVersion >= 10 ? 'c.is_identity as ii,' : '';
args.databaseName = this.connectionConfig.connection.database; args.databaseName = this.connectionConfig.connection.database;
const response = await this.sqlClient.raw( const response = await this.sqlClient.raw(
`select `select
@ -800,6 +812,7 @@ class PGClient extends KnexClient {
-- c.collation_name as clnn, -- c.collation_name as clnn,
pk.ordinal_position as pk_ordinal_position, pk.constraint_name as pk_constraint_name, pk.ordinal_position as pk_ordinal_position, pk.constraint_name as pk_constraint_name,
c.udt_name, c.udt_name,
${identitySelector}
(SELECT count(*) (SELECT count(*)
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc1 FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc1
@ -893,6 +906,13 @@ class PGClient extends KnexClient {
column.dtxp = response.rows[i].enum_values; column.dtxp = response.rows[i].enum_values;
} }
// handle identity column
if (+majorVersion >= 10) {
if (response.rows[i].ii === 'YES') {
column.ai = true;
}
}
columns.push(column); columns.push(column);
} }

Loading…
Cancel
Save