nene / sql-parser-cst

Parses SQL into Concrete Syntax Tree (CST)
GNU General Public License v2.0
115 stars 7 forks source link

Postgres CREATE TYPE #77

Closed maheshsundaram closed 4 weeks ago

maheshsundaram commented 4 weeks ago

Hi, really big fan of this project!

It looks like "create type" should be supported according to #46 but I ran into this issue: using "create type" throws FormattedSyntaxError:

create type color as enum ('blue', 'green', 'red')
 $ node --version
v21.7.1

$ node
> let { parse } = await import("sql-parser-cst")

> parse("create type color as enum ('blue', 'green', 'red');", { dialect: "postgresql" })
Uncaught FormattedSyntaxError: Syntax Error: Unexpected "type"
Was expecting to see: "CONSTRAINT", "DATABASE", "EXTERNAL", "FOREIGN", "FULLTEXT", "FUNCTION", "GLOBAL", "INDEX", "LOCAL", "MATERIALIZED", "OR", "PROCEDURE", "RECURSIVE", "SCHEMA", "SEARCH", "SEQUENCE", "SNAPSHOT", "SPATIAL", "TABLE", "TEMP", "TEMPORARY", "TRIGGER", "UNIQUE", "UNLOGGED", "VECTOR", "VIEW", "VIRTUAL", or whitespace
--> undefined:1:8
  |
1 | create type color as enum ('blue', 'green', 'red');
  |        ^
    at parse (/home/aum/code/maheshsundaram/sql-parser-cst/node_modules/sql-parser-cst/lib/main.js:40:19)
nene commented 4 weeks ago

I think you misread that issue description. It does mention support for user defined types, but in the context of that issue, it only means the ability to reference user defined types. Like inside CREATE TABLE or CAST() syntax.

Regarding CREATE TYPE statement, I haven't even started planning its support.

nene commented 4 weeks ago

To reduce the possible confusion over this, I created a separate issue for CREATE TYPE support