xnuinside / simple-ddl-parser

Simple DDL Parser to parse SQL (HQL, TSQL, AWS Redshift, BigQuery, Snowflake and other dialects) ddl files to json/python dict with full information about columns: types, defaults, primary keys, etc. & table properties, types, domains, etc.
MIT License
186 stars 42 forks source link

GENERATED BY DEFAULT and CONSTRAINT with CHECK #268

Open erwin-frohsinn opened 4 months ago

erwin-frohsinn commented 4 months ago

Describe the bug The following is not parsed:

CREATE TABLE pole.t_zuschauer (
    id int4 GENERATED BY DEFAULT AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START 1 CACHE 1 NO CYCLE) NOT NULL, -- Zuschauer-Nr.(Primärschlüssel)
    email varchar(50) NULL, -- email-Adresse
    CONSTRAINT t_zuschauer_email CHECK (((email IS NULL) OR ((email)::text = ''::text) OR ((email)::text ~* '([a-zA-Z0-9._%+-]+)@([a-zA-Z0-9.-]+)\.[a-zA-Z]{2,}'::text))),
    CONSTRAINT t_zuschauer_id PRIMARY KEY (id)
);

To Reproduce Parse with simple_ddl_parser

Desktop (please complete the following information):

Probable causes: id contains valid ddl code but prevents the columns from being parsed the constraint which checks the the email is not accepted

nhatndq-nals commented 3 months ago

I have same issue:

CREATE TABLE public.warranty_warrantydocument (
    id int8 GENERATED BY DEFAULT AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL,
    user_uuid uuid NULL,
    warranty_id int8 NOT NULL,
    CONSTRAINT warranty_warrantydocument_user_uuid_key UNIQUE (user_uuid),
    CONSTRAINT warranty_warrantydocument_pkey PRIMARY KEY (id),
    CONSTRAINT warranty_warrantydoc_warranty_id_073e66df_fk_warranty_ FOREIGN KEY (warranty_id) REFERENCES public.warranty(id) DEFERRABLE INITIALLY DEFERRED
);

This table info not in data json