Skip to content

Quote schema and table separately in sql-insert and sql-update output - #1669

Open
jayhemnani9910 wants to merge 1 commit into
dbcli:mainfrom
jayhemnani9910:sql-output-quote-schema
Open

jayhemnani9910 wants to merge 1 commit into
dbcli:mainfrom
jayhemnani9910:sql-output-quote-schema

Conversation

@jayhemnani9910

Copy link
Copy Markdown

Description

For a query on a schema-qualified table, \T sql-insert and sql-update quote the schema and the table as one name:

postgres> \T sql-insert
postgres> select id, name from app.people;
INSERT INTO "app.people" ("id", "name") VALUES

psql: ERROR: relation "app.people" does not exist. The adapter built "{}.{}".format(schema, table) and then wrapped it in one pair of quotes. The schema and the table are now quoted on their own, giving "app"."people". A plain table still gives "people".

Tested: new test_output_sql_insert_quotes_schema_and_table_apart fails without the change; pytest tests (without features and the ssh tunnel test) 2674 passed, 2673 on main. Against PostgreSQL 18, the output for app.people loads back with psql.

Checklist

  • I searched the existing issues and pull requests on this topic and linked them above (see "Before Opening a Pull Request" in CONTRIBUTING.rst).
  • I've added this contribution to the changelog.rst.
  • I've added my name to the AUTHORS file (or it's already there). It's added in Show arrays in Postgres format with the default data formats #1664.
  • I installed pre-commit hooks (pip install pre-commit && pre-commit install).
  • I verified that my changes work as expected (this may include manually testing them in your local environment, or in other available environments). Cross this out if not relevant (for example, if you're making a documentation change).
  • Please squash merge this pull request (uncheck if you'd like us to merge as multiple commits)

The table name was built as schema.table and then quoted once, so a query
on public.people gave INSERT INTO "public.people", a table that does not
exist.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant