andialbrecht / sqlparse

A non-validating SQL parser module for Python
BSD 3-Clause "New" or "Revised" License
3.63k stars 685 forks source link

sqlparse - constraint with check break down with error #729

Closed panwlodek closed 11 months ago

panwlodek commented 11 months ago

In my Version of sqlparse (0.4.4) is an error comming by the analyse of statements, with CONSTRAINT and CHECK f.e.:

CREATE TABLE public."tp_timeentry" ( id integer NOT NULL, line_no integer, date date NOT NULL, worked double precision NOT NULL, billable double precision NOT NULL, comment text NOT NULL, sub_account_id integer NOT NULL, time_file_id integer NOT NULL, CONSTRAINT "tp_timeentry_line_no_check" CHECK ((line_no >= 0)) );

The error message is following: Could not parse statement: (and the statement above)

andialbrecht commented 11 months ago

Could you give an example on how to reproduce this error?

So far, everything seems fine:

>>> import sqlparse
>>> sql = """CREATE TABLE public."tp_timeentry" (
... id integer NOT NULL,
... line_no integer,
... date date NOT NULL,
... worked double precision NOT NULL,
... billable double precision NOT NULL,
... comment text NOT NULL,
... sub_account_id integer NOT NULL,
... time_file_id integer NOT NULL,
... CONSTRAINT "tp_timeentry_line_no_check" CHECK ((line_no >= 0))
... );"""
>>> p = sqlparse.parse(sql)[0]
>>> p
<Statement 'CREATE...' at 0x111F3D8C0>
panwlodek commented 11 months ago

Hi Andy, you have right, the some answer have I if I try to call it directly with sqlparse like you described in your answer. The error, that I saw is coming by calling of pg_diagram and because the pg_diagram use the sqlparse I thought, that is the error from sqlparse. Sorry

andialbrecht commented 11 months ago

@panwlodek thanks for the feedback!