From f9545eaf7f171ded618763e24012cd98c7eb6c7c Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Fri, 14 May 2021 16:44:48 +0200 Subject: [PATCH] CockroachDB analysis #112 --- plugins/dbgate-plugin-postgres/src/backend/driver.js | 8 +++++++- .../src/backend/sql/tableModifications.js | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/dbgate-plugin-postgres/src/backend/driver.js b/plugins/dbgate-plugin-postgres/src/backend/driver.js index 53a20414..9b7444af 100644 --- a/plugins/dbgate-plugin-postgres/src/backend/driver.js +++ b/plugins/dbgate-plugin-postgres/src/backend/driver.js @@ -122,7 +122,13 @@ const driver = { return { rows: res.rows.map(row => zipDataRow(row, columns)), columns }; }, async stream(client, sql, options) { - const sqlSplitted = identify(sql, { dialect: 'psql', strict: false }); + let sqlSplitted; + try { + sqlSplitted = identify(sql, { dialect: 'psql', strict: false }); + } catch (e) { + // workaround + sqlSplitted = [{ text: sql }]; + } for (const sqlItem of sqlSplitted) { await runStreamItem(client, sqlItem.text, options); diff --git a/plugins/dbgate-plugin-postgres/src/backend/sql/tableModifications.js b/plugins/dbgate-plugin-postgres/src/backend/sql/tableModifications.js index 82928188..4af0e34b 100644 --- a/plugins/dbgate-plugin-postgres/src/backend/sql/tableModifications.js +++ b/plugins/dbgate-plugin-postgres/src/backend/sql/tableModifications.js @@ -47,6 +47,8 @@ from AND n.nspname !~ '^pg_toast' ORDER BY a.attnum ) as tabledefinition +inner join information_schema.tables on tables.table_schema = tabledefinition.nspname and tables.table_name = tabledefinition.relname +and tables.table_type not like '%VIEW%' where ('tables:' || nspname || '.' || relname) =OBJECT_ID_CONDITION group by relname, nspname, oid `;