Skip to content

Commit 9f6ff6e

Browse files
committed
Rely on information_schema.columns for schema list
A UNION was added in getredash#3599 which is incorrect: this results in duplicate column names (because of a NULL data type) for partitioned tables and foreign tables.
1 parent 12e9ab7 commit 9f6ff6e

File tree

1 file changed

+2
-32
lines changed

1 file changed

+2
-32
lines changed

redash/query_runner/pg.py

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -204,45 +204,15 @@ def _get_definitions(self, schema, query):
204204
build_schema(results, schema)
205205

206206
def _get_tables(self, schema):
207-
"""
208-
relkind constants per https://www.postgresql.org/docs/10/static/catalog-pg-class.html
209-
r = regular table
210-
v = view
211-
m = materialized view
212-
f = foreign table
213-
p = partitioned table (new in 10)
214-
---
215-
i = index
216-
S = sequence
217-
t = TOAST table
218-
c = composite type
219-
"""
220-
221207
query = """
222-
SELECT s.nspname as table_schema,
223-
c.relname as table_name,
224-
a.attname as column_name,
225-
null as data_type
226-
FROM pg_class c
227-
JOIN pg_namespace s
228-
ON c.relnamespace = s.oid
229-
AND s.nspname NOT IN ('pg_catalog', 'information_schema')
230-
JOIN pg_attribute a
231-
ON a.attrelid = c.oid
232-
AND a.attnum > 0
233-
AND NOT a.attisdropped
234-
WHERE c.relkind IN ('m', 'f', 'p')
235-
AND has_table_privilege(s.nspname || '.' || c.relname, 'select')
236-
AND has_schema_privilege(s.nspname, 'usage')
237-
238-
UNION
239-
240208
SELECT table_schema,
241209
table_name,
242210
column_name,
243211
data_type
244212
FROM information_schema.columns
245213
WHERE table_schema NOT IN ('pg_catalog', 'information_schema')
214+
AND has_table_privilege(table_schema || '.' || table_name, 'select')
215+
AND has_schema_privilege(table_schema, 'usage')
246216
"""
247217

248218
self._get_definitions(schema, query)

0 commit comments

Comments
 (0)