TSQL: PRIMARY KEY constraint fails to parse if sort option is given #4610
Closed
Description
The following CREATE TABLE statement parses just fine:
import sqlglot
test = """CREATE TABLE dbo.test (
id INT,
name VARCHAR(50),
CONSTRAINT pk_testTable PRIMARY KEY (id)
) ;"""
parsed_script = sqlglot.parse(test, read="tsql")
However, when I add ASC or DESC to the PRIMARY KEY constraint, it fails to parse:
import sqlglot
test = """CREATE TABLE dbo.test (
id INT,
name VARCHAR(50),
CONSTRAINT pk_testTable PRIMARY KEY (id DESC)
) ;"""
parsed_script = sqlglot.parse(test, read="tsql")
Error Message:
Exception has occurred: ParseError
Expecting ). Line 4, Col: 45.
bo.test (
id INT,
name VARCHAR(50),
CONSTRAINT pk_testTable PRIMARY KEY (id �[4mDESC�[0m)
) ;
File "C:\*snip*\main.py", line 96, in main
parsed_script = sqlglot.parse(test, read="tsql")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\*snip*\main.py", line 116, in <module>
main()
sqlglot.errors.ParseError: Expecting ). Line 4, Col: 45.
bo.test (
id INT,
name VARCHAR(50),
CONSTRAINT pk_testTable PRIMARY KEY (id �[4mDESC�[0m)
) ;
Official Documentation: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-table-transact-sql?view=sql-server-ver16#constraint
Edit: sqlglot version is 25.21.3.
Metadata
Assignees
Labels
No labels