diff --git a/redash/query_runner/pg.py b/redash/query_runner/pg.py index ca071bb627..c7ddef1eb7 100644 --- a/redash/query_runner/pg.py +++ b/redash/query_runner/pg.py @@ -388,12 +388,13 @@ def _get_tables(self, schema): SELECT DISTINCT table_name, table_schema, column_name, + data_type, ordinal_position AS pos FROM svv_columns WHERE table_schema NOT IN ('pg_internal','pg_catalog','information_schema') AND table_schema NOT LIKE 'pg_temp_%' ) - SELECT table_name, table_schema, column_name + SELECT table_name, table_schema, column_name, data_type FROM tables WHERE HAS_SCHEMA_PRIVILEGE(table_schema, 'USAGE') AND diff --git a/tests/query_runner/test_pg.py b/tests/query_runner/test_pg.py index 634547be04..e72001b0a9 100644 --- a/tests/query_runner/test_pg.py +++ b/tests/query_runner/test_pg.py @@ -25,3 +25,19 @@ def test_handles_dups_between_public_and_other_schemas(self): self.assertListEqual(schema["main.users"]["columns"], ["id", "name"]) self.assertIn('public."main.users"', schema.keys()) self.assertListEqual(schema['public."main.users"']["columns"], ["id"]) + + def test_build_schema_with_data_types(self): + results = { + "rows": [ + {"table_schema": "main", "table_name": "users", "column_name": "id", "data_type": "integer"}, + {"table_schema": "main", "table_name": "users", "column_name": "name", "data_type": "varchar"}, + ] + } + + schema = {} + + build_schema(results, schema) + + self.assertListEqual( + schema["main.users"]["columns"], [{"name": "id", "type": "integer"}, {"name": "name", "type": "varchar"}] + )