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

deparse altered "CREATE TABLE" statement, removed quotes from CONSTRAINT name #48

Open
divyenduz opened this issue Oct 21, 2021 · 0 comments

Comments

@divyenduz
Copy link

divyenduz commented Oct 21, 2021

Original query (with fingerprint 91291afafdacd92a):

CREATE TABLE "Album"
(
  "AlbumId" INT NOT NULL,
  "Title" VARCHAR(160) NOT NULL,
  "ArtistId" INT NOT NULL,
  CONSTRAINT "PK_Album" PRIMARY KEY  ("AlbumId")
)

Deparsed query (with fingerprint d37da9dd17c1175d):

CREATE TABLE "Album" (
 	"AlbumId" int NOT NULL,
	"Title" varchar(160) NOT NULL,
	"ArtistId" int NOT NULL,
	CONSTRAINT PK_Album PRIMARY KEY ( "AlbumId" ) 
);

In the deparsed query, double quotes around PK_Album are removed. I am not sure if this makes the queries different but since the fingerprint changed, I raised this issue.

This is also true for "ALTER TABLE". Please let me know if I should open a separate issue for that.

To reproduce:

const fs = require('fs')
const { parse, deparse } = require('pgsql-parser');

async function main() {
    const stmts = parse(`
CREATE TABLE "Album"
(
  "AlbumId" INT NOT NULL,
  "Title" VARCHAR(160) NOT NULL,
  "ArtistId" INT NOT NULL,
  CONSTRAINT "PK_Album" PRIMARY KEY  ("AlbumId")
)
    `)
    const stmts2 = deparse(stmts[0])
    console.log(stmts2)
}

main()

Schema at https://github.com/prisma/database-schema-examples/tree/main/postgres/chinook

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

No branches or pull requests

1 participant