Skip to content

Commit

Permalink
fix(redshift): listcolumns doesn't return any results for views with …
Browse files Browse the repository at this point in the history
…no schema binding (#91)

# Description
Using `SVV_COLUMNS` for listing column which supports local and external
tables and views, including [late-binding
views](https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_VIEW.html#r_CREATE_VIEW_late-binding-views).

## Linear Ticket
REV-1042

## Security
- [x] The code changed/added as part of this pull request won't create
any security issues with how the software is being used.

---------

Co-authored-by: Vikas Venkatraman <[email protected]>
  • Loading branch information
Vikas26021999 and Vikas Venkatraman authored Jun 7, 2024
1 parent f210281 commit 9489790
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions sqlconnect/internal/redshift/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ func NewDB(credentialsJSON json.RawMessage) (*DB, error) {
cmds.SchemaExists = func(schema base.UnquotedIdentifier) string {
return fmt.Sprintf("SELECT schema_name FROM svv_redshift_schemas WHERE schema_name = '%[1]s'", schema)
}
cmds.ListColumns = func(catalog, schema, table base.UnquotedIdentifier) (string, string, string) {
stmt := fmt.Sprintf("SELECT column_name, data_type FROM SVV_COLUMNS WHERE table_schema = '%[1]s' AND table_name = '%[2]s'", schema, table)
if catalog != "" {
stmt += fmt.Sprintf(" AND table_catalog = '%[1]s'", catalog)
}
return stmt + " ORDER BY ordinal_position ASC", "column_name", "data_type"
}
return cmds
}),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"_character": "string",
"_date": "datetime",
"_time": "time without time zone",
"_timetz": "time with time zone",
"_timetz": "timetz",
"_timestamptz": "datetime",
"_timestampntz": "datetime",
"_timestampwtz": "datetime",
Expand Down

0 comments on commit 9489790

Please sign in to comment.