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 INDEX" statement, removed double quotes from index name, columns list and removed USING clause #47

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

Comments

@divyenduz
Copy link

divyenduz commented Oct 21, 2021

Original query (with fingerprint a1aa8bc11a444439):

CREATE INDEX "existing_undispatched_message" ON public.messages USING btree ("context_id", context_type, notification_name, "to", user_id)

Deparsed query (with fingerprint 0):

CREATE INDEX existing_undispatched_message ON public.messages ( context_id, context_type, notification_name, to, user_id );

It changed the following:-

  1. Removed double quotes from index name
  2. Removed double quotes from columns list
  3. Removed USING clause

Please let me know if I should create 3 different issues for these.

This also applies to CREATE UNIQUE INDEX. Please let me know if I should make two separate issues for this :)

To reproduce:

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

async function main() {
    const stmts = parse(`
CREATE INDEX "existing_undispatched_message" ON public.messages USING btree ("context_id", context_type, notification_name, "to", user_id)
    `)
    const stmts2 = deparse(stmts[0])
    console.log(stmts2)
}

main()

In this specific case, since it changed "to" to to, the query became not parseable and trying to parse it fails with

syntax error at or near "to"

Here is another case that would generate an invalid deparsed query because of the word primary

CREATE UNIQUE INDEX index_user_emails_on_user_id_and_primary ON public.user_emails USING btree (user_id, "primary") WHERE "primary"

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

@divyenduz divyenduz changed the title deparse altered "CREATE INDEX" statement, removed double quotes from columns list and USING clause deparse altered "CREATE INDEX" statement, removed double quotes from columns list and removed USING clause Oct 21, 2021
@divyenduz divyenduz changed the title deparse altered "CREATE INDEX" statement, removed double quotes from columns list and removed USING clause deparse altered "CREATE INDEX" statement, removed double quotes from index name, columns list and removed USING clause Oct 21, 2021
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