Skip to content

deparse altered "COMMENT ON COLUMN" statement, the string is escaped and a ' is removed #50

@divyenduz

Description

@divyenduz

Original query (with fingerprint 7bbdf5f425075dd4):

COMMENT ON COLUMN public.posts.reply_to_post_number IS 'If this post is a reply to another, this column is the post_number of the post it''s replying to. [FKEY posts.topic_id, posts.post_number]'

Deparsed query (with fingerprint 0):

COMMENT ON COLUMN public.posts.reply_to_post_number IS E'If this post is a reply to another, this column is the post_number of the post it's replying to. [FKEY posts.topic_id, posts.post_number]';
  • The deparsed query also fails parsing with Error: syntax error at or near "s" 🤔

To reproduce:

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

async function main() {
    const stmts = parse(`
COMMENT ON COLUMN public.posts.reply_to_post_number IS 'If this post is a reply to another, this column is the post_number of the post it''s replying to. [FKEY posts.topic_id, posts.post_number]'
    `)
    const stmts2 = deparse(stmts[0])
    console.log(stmts2)
}

main()

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions