From 06036e2fe800d138ef3f0d38d73f5fcf38057f61 Mon Sep 17 00:00:00 2001 From: Rafa de la Torre Date: Wed, 10 Feb 2016 18:58:01 +0100 Subject: [PATCH] Quote identifiers returned by CDB_QueryTables_Updated_At --- scripts-available/CDB_ForeignTable.sql | 11 ++++++----- test/extension/test.sh | 9 +++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/scripts-available/CDB_ForeignTable.sql b/scripts-available/CDB_ForeignTable.sql index a7ef87e..f39e1f8 100644 --- a/scripts-available/CDB_ForeignTable.sql +++ b/scripts-available/CDB_ForeignTable.sql @@ -159,11 +159,12 @@ AS $$ ), fqtn AS ( SELECT - (CASE WHEN c.relkind = 'f' THEN cartodb._cdb_dbname_of_foreign_table(query_tables_oid.reloid) - ELSE current_database() - END)::text AS dbname, - n.nspname::text schema_name, - c.relname::text table_name, + quote_ident( + (CASE WHEN c.relkind = 'f' THEN cartodb._cdb_dbname_of_foreign_table(query_tables_oid.reloid) + ELSE current_database() + END)::text) AS dbname, + quote_ident(n.nspname::text) schema_name, + quote_ident(c.relname::text) table_name, c.relkind, query_tables_oid.reloid FROM query_tables_oid, pg_catalog.pg_class c diff --git a/test/extension/test.sh b/test/extension/test.sh index cf9f830..37a5406 100755 --- a/test/extension/test.sh +++ b/test/extension/test.sh @@ -501,6 +501,15 @@ local' sql postgres "SELECT cartodb.CDB_Last_Updated_Time('{test_fdw.foo,public.local}'::text[]) < now()" should 't' sql postgres "SELECT cartodb.CDB_Last_Updated_Time('{test_fdw.foo,public.local}'::text[]) > (now() - interval '1 minute')" should 't' + # Check we quote names on output as needed (as CDB_QueryTablesText does) + sql postgres 'CREATE TABLE "local-table-with-dashes" (c int)'; + sql postgres 'INSERT INTO "local-table-with-dashes" (c) VALUES (44)'; + sql postgres "SELECT cdb_tablemetadatatouch('public.local-table-with-dashes'::regclass);" + query='$query$ SELECT * FROM test_fdw.foo, local, public."local-table-with-dashes" $query$::text' + sql postgres "SELECT dbname, schema_name, table_name FROM cartodb.CDB_QueryTables_Updated_At(${query}) ORDER BY dbname, schema_name, table_name;" should 'fdw_target|test_fdw|foo +test_extension|public|local +test_extension|public|"local-table-with-dashes"' + DATABASE=fdw_target sql postgres 'REVOKE USAGE ON SCHEMA test_fdw FROM fdw_user;' DATABASE=fdw_target sql postgres 'REVOKE SELECT ON test_fdw.foo FROM fdw_user;' DATABASE=fdw_target sql postgres 'REVOKE SELECT ON cdb_tablemetadata FROM fdw_user;'