Skip to content
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

PostgreSQL table names not quoted: UndefinedTable relation "public.whatever" does not exist for table "Whatever" #2128

Open
isosphere opened this issue Nov 19, 2023 · 3 comments
Labels

Comments

@isosphere
Copy link
Contributor

Small description

Connected to a local PostgreSQL database. PgTablesSheet looks good. Press "Enter" on any table that is not exclusively lowercase, get the error in the title.

Try with another table, and always get InFailedSqlTransaction: current transaction is aborted

Expected result
I should see the table I selected

Actual result with screenshot
image

If you get an unexpected error, please include the full stack trace that you get with Ctrl-E.
image

As you can see from the stack trace, the table identifier is not quoted. In PostgreSQL, public.HelloWorld is interpreted as public.helloworld. If the actual table name is public.HelloWorld, you have to use quotes. This applies for columns, too. You can solve this by always quoting identifiers.

Additional context
Please include the version of VisiData and Python.

VisiData 2.11,1, Python 3.10.4

@isosphere isosphere added the bug label Nov 19, 2023
@isosphere
Copy link
Contributor Author

I think we just have to change:

with self.sql.cur(f"SELECT * FROM {source}") as cur:

To read:

with self.sql.cur(f'SELECT * FROM "{source}"') as cur:

@saulpw
Copy link
Owner

saulpw commented Nov 19, 2023

@isosphere would you be willing to test that change and submit a PR?

isosphere added a commit to isosphere/visidata that referenced this issue Nov 20, 2023
Without this, non-lowercase objects cannot be loaded.

saulpw#2128
@isosphere
Copy link
Contributor Author

with self.sql.cur(f'SELECT * FROM "{source}"') as cur:

PR submitted; my proposed solution in this quote was not enough, as "public.TableName" refers to the literal object named "public.TableName", not schema public, table TableName. I've quoted them separately, which works.

isosphere added a commit to isosphere/visidata that referenced this issue Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants