nene / sql-parser-cst

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

Postgres support (basic syntax) #42

Open nene opened 6 months ago

nene commented 6 months ago

Basic syntax

karlhorky commented 5 months ago

Not sure if listing out missing features is wanted in this issue, but I saw on SQL Explorer that now() functions are also not supported for PostgreSQL:

CREATE TABLE users ( created_at timestamp DEFAULT now() );
Syntax Error: Unexpected "now"
Was expecting to see: "(", "DATE", "DATETIME", "FALSE", "NULL", "TIME", "TIMESTAMP", "TRUE", "X", number, or string
--> undefined:1:51
  |
1 | CREATE TABLE users ( created_at timestamp DEFAULT now() );
  |                                                   ^

Maybe this is already covered under Keywords -> Restrict certain keywords as function or type names?

nene commented 5 months ago

Well, always good to have examples of not supported code. Don't really know what the issue might be in here. Possibly indeed related to Postgres keyword handling.

nene commented 4 months ago

@karlhorky FYI, this error happens currently because the DEFAULT value implementation is based on the existing SQLite and BigQuery implementation. In these dialects only literal values or a parenthesized expression can be used as default value. So the following parses fine:

CREATE TABLE users ( created_at timestamp DEFAULT (now()) );
jming422 commented 3 months ago

Thanks for your work on this! I've been experimenting with the Prettier plugin using this parser and overall it's been great.

Parameters: $foo

In PostgreSQL, parameters are typically referred to by position number instead of by name (docs) -- would it be possible to add a $nr param type similar to ?nr but with a dollar sign?

nene commented 3 months ago

Yeah, that should be simple to add.

nene commented 3 months ago

@jming422 Should be available in 0.27.1 release.

jming422 commented 3 months ago

Should be available in 0.27.1 release.

Woah, thank you, you rock! 🚀

nene commented 3 months ago

Also pushed a new prettier plugin release.