Skip to content

Commit

Permalink
Merge pull request #160 from bibhuty-did-this/bibhuty/fix/ignore-defa…
Browse files Browse the repository at this point in the history
…ult-column-for-views

feat: ignore default column for views
  • Loading branch information
aravindet authored May 23, 2024
2 parents 575c7e9 + 06afd2e commit 2bf1f53
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/pg/Db.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,16 @@ export default class Db {
if (tableOptions.schema) return;
const { table, verCol, joins } = tableOptions;

const tableSchema = (
const tableInfoSchema = (
await this.query(sqlTag`
SELECT table_schema
SELECT table_schema, table_type
FROM information_schema.tables
WHERE table_name = ${table}
ORDER BY array_position(current_schemas(false)::text[], table_schema::text) ASC
LIMIT 1`)
).rows[0].table_schema;
).rows[0];
const tableSchema = tableInfoSchema.table_schema;
const tableType = tableInfoSchema.table_type;

const types = (
await this.query(sqlTag`
Expand Down Expand Up @@ -143,7 +145,7 @@ export default class Db {
column_name = ${verCol}`)
).rows[0].column_default;

if (!verDefault) {
if (!verDefault && tableType !== 'VIEW') {
throw Error(`pg.verCol_without_default ${verCol}`);
}

Expand Down

0 comments on commit 2bf1f53

Please sign in to comment.