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 WITHOUT TIME ZONE #55

Closed
divyenduz opened this issue Oct 22, 2021 · 6 comments
Closed

Comments

@divyenduz
Copy link

Original query (with fingerprint 2c0d1f29c30f5177):

  CREATE TABLE public."AO_563AEE_ACTIVITY_ENTITY" (
    "ACTIVITY_ID" bigint NOT NULL,
    "ACTOR_ID" integer,
    "CONTENT" text,
    "GENERATOR_DISPLAY_NAME" character varying(255),
    "GENERATOR_ID" character varying(450),
    "ICON_ID" integer,
    "ID" character varying(450),
    "ISSUE_KEY" character varying(255),
    "OBJECT_ID" integer,
    "POSTER" character varying(255),
    "PROJECT_KEY" character varying(255),
    "PUBLISHED" timestamp without time zone,
    "TARGET_ID" integer,
    "TITLE" character varying(255),
    "URL" character varying(450),
    "USERNAME" character varying(255),
    "VERB" character varying(450)
  )

Deparsed query (with fingerprint 13401b610a7be108):

CREATE TABLE public.AO_563AEE_ACTIVITY_ENTITY (
 	ACTIVITY_ID bigint NOT NULL,
	ACTOR_ID int,
	CONTENT text,
	GENERATOR_DISPLAY_NAME varchar(255),
	GENERATOR_ID varchar(450),
	ICON_ID int,
	ID varchar(450),
	ISSUE_KEY varchar(255),
	OBJECT_ID int,
	POSTER varchar(255),
	PROJECT_KEY varchar(255),
	PUBLISHED timestamp,
	TARGET_ID int,
	TITLE varchar(255),
	URL varchar(450),
	USERNAME varchar(255),
	VERB varchar(450) 
);
  • On field "PUBLISHED", the type was changed from timestamp without timezone to timestamp.

To reproduce:

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

async function main() {
    const stmts = parse(`
        CREATE TABLE public."AO_563AEE_ACTIVITY_ENTITY" (
    "ACTIVITY_ID" bigint NOT NULL,
    "ACTOR_ID" integer,
    "CONTENT" text,
    "GENERATOR_DISPLAY_NAME" character varying(255),
    "GENERATOR_ID" character varying(450),
    "ICON_ID" integer,
    "ID" character varying(450),
    "ISSUE_KEY" character varying(255),
    "OBJECT_ID" integer,
    "POSTER" character varying(255),
    "PROJECT_KEY" character varying(255),
    "PUBLISHED" timestamp without time zone,
    "TARGET_ID" integer,
    "TITLE" character varying(255),
    "URL" character varying(450),
    "USERNAME" character varying(255),
    "VERB" character varying(450)
  )
    `)
    const stmts2 = deparse(stmts[0])
    console.log(stmts2)
}

main()

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

@pyramation
Copy link
Collaborator

so this is not technically a bug since timestamp is by definition without timezone. The AST produces the same syntax regardless of variations. Does that make sense?

https://www.postgresql.org/docs/9.1/datatype-datetime.html

So in your example, the type wasn't actually changed, but the syntax expressing it was.

@divyenduz
Copy link
Author

Curious, it makes sense but I don't understand why the query fingerprint changed. Isn't finger print supposed to remain same for various syntaxes of the same query? 🤔

@pyramation
Copy link
Collaborator

two queries can create the same AST. One AST, however, can only create one query.

@divyenduz
Copy link
Author

Thank you, but do you think that fingerprint of two queries which produce the same AST should be the same?

@pyramation
Copy link
Collaborator

what I'm suggesting is that, the deparser is not a bijective function, in other words It's lossy. So I think the fingerprints of two different queries should each be unique, however, once they are passed through the parser/deparser and back, they would only ever produce one query and thus one fingerprint.

@divyenduz
Copy link
Author

Got it, thank you for taking the time to explain.

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

2 participants