pgschema icon indicating copy to clipboard operation
pgschema copied to clipboard

Altering tables with quoted identifiers does not quote them

Open PadenZach opened this issue 10 months ago • 1 comments

Starting with:

-- example initial
create schema example;

CREATE TABLE example.ex ("ID" int primary key);

Then later updating it to:

-- example after
create schema example;

-- This is just changing int -> bigint
CREATE TABLE example.ex ("ID" bigint primary key);

Results in:

Plan: 1 to modify.

Summary by type:
  tables: 1 to modify

Tables:
  ~ ex
    ~ ID (column)

DDL to be executed:
--------------------------------------------------

ALTER TABLE ex ALTER COLUMN ID TYPE bigint;

Do you want to apply these changes? (yes/no): yes

Applying changes...
time=2026-01-29T19:04:29.316-06:00 level=DEBUG msg="Attempting database connection" host=localhost port=5432 database=postgres user=postgres sslmode=prefer application_name=pgschema
time=2026-01-29T19:04:29.331-06:00 level=DEBUG msg="Database connection established successfully"
time=2026-01-29T19:04:29.331-06:00 level=DEBUG msg="Executing SQL" description="set search_path to target schema" sql="SET search_path TO example, public"
time=2026-01-29T19:04:29.332-06:00 level=DEBUG msg="SQL execution succeeded" description="set search_path to target schema"
Set search_path to: example, public

Executing group 1/1...
  Executing 1 statements in implicit transaction
time=2026-01-29T19:04:29.332-06:00 level=DEBUG msg="Executing SQL" description="execute 1 statements in group 1" sql="ALTER TABLE ex ALTER COLUMN ID TYPE bigint;;"
time=2026-01-29T19:04:29.333-06:00 level=DEBUG msg="SQL execution failed" description="execute 1 statements in group 1" error="ERROR: column \"id\" of relation \"ex\" does not exist (SQLSTATE 42703)"
Error: failed to execute concatenated statements in group 1: ERROR: column "id" of relation "ex" does not exist (SQLSTATE 42703)

As we can see this ends up issuing the identifier in an unquoted fashion, which is not valid.

In the example case here, we could easily just use an unquoted identifier, but, there are some cases where we cannot (especially for larger projects that may wish to migrate to this tool).

PadenZach avatar Jan 30 '26 01:01 PadenZach

Looking into fixing this one myself, probably have a PR open by EOD.

PadenZach avatar Jan 30 '26 21:01 PadenZach