10000 fix: Return None when retrieving the oid for an external table by Vitor-Avila · Pull Request #305 · sqlalchemy-redshift/sqlalchemy-redshift · GitHub
[go: up one dir, main page]

Skip to content

fix: Return None when retrieving the oid for an external table #305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 36 additions & 10 deletions sqlalchemy_redshift/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,21 +792,47 @@ def get_check_constraints(self, connection, table_name, schema=None, **kw):
@reflection.cache
def get_table_oid(self, connection, table_name, schema=None, **kw):
"""Fetch the oid for schema.table_name.
Return null if not found (external table does not have table oid)"""
Return None if not found (external table does not have table oid)"""
schema_field = '"{schema}".'.format(schema=schema) if schema else ""

result = connection.execute(
sa.text(
"""
select '{schema_field}"{table_name}"'::regclass::oid;
""".format(
schema_field=schema_field,
table_name=table_name
try:
result = connection.execute(
sa.text(
"""
select '{schema_field}"{table_name}"'::regclass::oid;
""".format(
schema_field=schema_field,
table_name=table_name
)
)
)
)

return result.scalar()
return result.scalar()
except Exception as e:
# Gracefully handle external tables
schema_filter = (
"AND schemaname = '{schema}'".format(schema=schema)
if schema else ""
)
result = connection.execute(
sa.text(
"""
SELECT
1
FROM svv_external_tables
WHERE
tablename = '{table_name}'
{schema_filter}
LIMIT 1;
""".format(
schema_filter=schema_filter,
table_name=table_name
)
)
)
if result.scalar() is not None:
return None
raise e

@reflection.cache
def get_pk_constraint(self, connection, table_name, schema=None, **kw):
Expand Down
0