Skip to content

Commit f1de031

Browse files
committed
fix: conversion error on identifiers
Things break when using indentifiers for tables/columns/etc. with spaces in the name--need to quote it.
1 parent 31c32d1 commit f1de031

File tree

5 files changed

+11
-12
lines changed

5 files changed

+11
-12
lines changed

src/lib/sql/columns.sql

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
-- We can uniquely point to a specific column using table_id + ordinal_position.
21
SELECT
32
c.oid AS table_id,
43
table_schema AS schema,
@@ -19,5 +18,5 @@ SELECT
1918
is_updatable::boolean
2019
FROM
2120
information_schema.columns
22-
JOIN pg_class c ON c.relnamespace = table_schema::text::regnamespace
23-
AND c.relname = table_name::text
21+
JOIN pg_class c ON quote_ident(table_schema)::regnamespace = c.relnamespace
22+
AND c.relname = table_name

src/lib/sql/grants.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ SELECT
1010
with_hierarchy :: boolean
1111
FROM
1212
information_schema.role_table_grants
13-
INNER JOIN pg_class c ON table_schema::text::regnamespace = c.relnamespace
14-
AND table_name::text = c.relname
13+
JOIN pg_class c ON quote_ident(table_schema)::regnamespace = c.relnamespace
14+
AND table_name = c.relname

src/lib/sql/schemas.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ SELECT
99
sql_path
1010
FROM
1111
information_schema.schemata
12-
JOIN pg_namespace nsp ON schema_name::text::regnamespace = nsp.oid
12+
JOIN pg_namespace nsp ON schema_name = nsp.nspname

src/lib/sql/tables.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ SELECT
55
table_name AS name,
66
is_insertable_into,
77
is_typed,
8-
pg_total_relation_size(table_schema || '.' || table_name) :: bigint AS bytes,
8+
pg_total_relation_size(format('%I.%I', table_schema, table_name))::bigint AS bytes,
99
pg_size_pretty(
10-
pg_total_relation_size(table_schema || '.' || table_name)
10+
pg_total_relation_size(format('%I.%I', table_schema, table_name))
1111
) AS size,
1212
seq_scan :: bigint AS seq_scan_count,
1313
seq_tup_read :: bigint AS seq_row_read_count,
@@ -30,8 +30,8 @@ SELECT
3030
autoanalyze_count :: bigint
3131
FROM
3232
information_schema.tables
33-
JOIN pg_class c ON c.relnamespace = table_schema::text::regnamespace
34-
AND c.relname = table_name::text
33+
JOIN pg_class c ON quote_ident(table_schema)::regnamespace = c.relnamespace
34+
AND c.relname = table_name
3535
LEFT JOIN pg_stat_user_tables ON pg_stat_user_tables.schemaname = tables.table_schema
3636
AND pg_stat_user_tables.relname = tables.table_name
3737
WHERE

src/lib/sql/views.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ SELECT
1010
is_trigger_insertable_into
1111
FROM
1212
information_schema.views
13-
INNER JOIN pg_class c ON table_schema::text::regnamespace = c.relnamespace
14-
AND table_name::text = c.relname
13+
JOIN pg_class c ON quote_ident(table_schema)::regnamespace = c.relnamespace
14+
AND table_name = c.relname

0 commit comments

Comments
 (0)