Skip to content

Commit 4d90b1b

Browse files
KSDaemonemmanuel
authored andcommitted
fix(redshift-driver): Use Redshift-specific schema query (cube-js#9363)
* fix(redshift-driver): Use Redshift schema query. Fixes cube-js#3876. * fix(redshift-driver): Use Redshift-specific schema query --------- Co-authored-by: Emmanuel Gomez <[email protected]>
1 parent ae67b8d commit 4d90b1b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

packages/cubejs-redshift-driver/src/RedshiftDriver.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,20 @@ export class RedshiftDriver extends PostgresDriver<RedshiftDriverConfiguration>
116116
`;
117117
}
118118

119+
/**
120+
* In Redshift schemas not owned by the current user are not shown in regular information_schema,
121+
* so it needs to be queried through the pg_namespace table. Because user might be granted specific
122+
* permissions on the concrete schema (like CREATE tables in already existing but not owned pre-aggregation schema).
123+
* @override
124+
*/
125+
public override async createSchemaIfNotExists(schemaName: string): Promise<void> {
126+
const schemaExistsQuery = `SELECT nspname FROM pg_namespace where nspname = ${this.param(0)}`;
127+
const schemas = await this.query(schemaExistsQuery, [schemaName]);
128+
if (schemas.length === 0) {
129+
await this.query(`CREATE SCHEMA IF NOT EXISTS ${schemaName}`, []);
130+
}
131+
}
132+
119133
/**
120134
* In Redshift external tables are not shown in regular Postgres information_schema,
121135
* so it needs to be queried separately.

0 commit comments

Comments
 (0)