sqlglot icon indicating copy to clipboard operation
sqlglot copied to clipboard

Postgres parsing falls back to command for `CREATE TYPE`

Open devfros opened this issue 6 months ago • 2 comments

First and foremost: thank you!


Currently, postgres types (enums) can only be processed using the fallback COMMAND expression.

It would be nice if we could get dedicated AST expression nodes for type creation.

Current behavior:

>>> from sqlglot import parse_one
>>> testsql = '''CREATE TYPE book_type as ENUM (
    'FICTION',
    'NONFICTION'
   )'''
>>> parse_one(testsql, 'postgres')
'''CREATE TYPE book_type AS ENUM (
    'FICTION',
    'NONFICTION'
)' contains unsupported syntax. Falling back to parsing as a 'Command'.'''

In a more ideal world, this would instead return eg an Create(Type) structure instead of just the command.

devfros avatar May 06 '26 11:05 devfros

I'd like to work on this myself. Is a PR welcome?

devfros avatar May 06 '26 11:05 devfros

@devfros More than welcome, thank you!

VaggelisD avatar May 06 '26 11:05 VaggelisD