Skip to content

Commit

Permalink
Add data type to redshift query runner (#7109)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
zachliu and github-actions[bot] authored Aug 5, 2024
1 parent 51ef625 commit a4f92a8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion redash/query_runner/pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions tests/query_runner/test_pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}]
)

0 comments on commit a4f92a8

Please sign in to comment.