sqlglot icon indicating copy to clipboard operation
sqlglot copied to clipboard

Postgres parser fails on schema-qualified `COMMENT ON TYPE` and `COMMENT ON VIEW`

Open devfros opened this issue 6 months ago • 2 comments

First, thank you for maintaining sqlglot. It has been very useful for my personal project.

Problem

sqlglot fails to parse valid PostgreSQL COMMENT ON statements when the target is schema-qualified for some object kinds, notably TYPE and VIEW.

Reproduction

from sqlglot import Dialects, parse

cases = [
    "COMMENT ON TYPE mood IS 'x';",
    "COMMENT ON TYPE foo.mood IS 'x';",
    "COMMENT ON VIEW foo.bat IS 'x';",
    "COMMENT ON TABLE foo.bar IS 'x';",
    "COMMENT ON COLUMN foo.bar.baz IS 'x';",
]

for sql in cases:
    print(sql)
    print(parse(sql, dialect=Dialects.POSTGRES))
ParseError: Required keyword: 'expression' missing for <class 'sqlglot.expressions.ddl.Comment'>.

devfros avatar May 27 '26 06:05 devfros

I can make a PR

devfros avatar May 27 '26 06:05 devfros

@devfros feel free making a PR, happy to review.

geooo109 avatar May 27 '26 07:05 geooo109