shinichi-takii / ddlparse

DDL parase and Convert to BigQuery JSON schema and DDL statements
https://pypi.org/project/ddlparse/
BSD 3-Clause "New" or "Revised" License
87 stars 29 forks source link

Parsing stops without error on default varying varchar #74

Open HerveMignot opened 2 years ago

HerveMignot commented 2 years ago

Hello,

the field "imputation" below has a default value definition that stops DdlParse to go farther. If you remove this default value definition (comment provided below), parsing is going on fine with the lastest columns.

This DDL is coming from a PG dump:

    --
    -- PostgreSQL database dump
    --

    -- Dumped from database version 9.6.22
    -- Dumped by pg_dump version 9.6.22

Example provided:

test_ddl = """
CREATE TABLE public.t_ref_structure (
id uuid NOT NULL,
"version" numeric NULL DEFAULT 0,
id_number int4 NULL,
created_date timestamptz NULL DEFAULT now(),
created_by varchar(240) NULL,
updated_date timestamptz NULL,
updated_by varchar(240) NULL,
check_cancel bool NOT NULL DEFAULT false,
cancel_date timestamptz NULL,
cancel_by varchar(240) NULL,
imputation varchar(10) NULL DEFAULT 'A'::character varying,
-- imputation varchar(10) NULL DEFAULT 'A',
ordre numeric NULL,
categorisation_sap varchar(240) NULL,
is_notifiable bool NULL DEFAULT false,
CONSTRAINT t_ref_structure_pkey PRIMARY KEY (id),
CONSTRAINT fk_str_imputation FOREIGN KEY (imputation) REFERENCES public.t_ref_imputation(code_imputation)
);
"""

parser = DdlParse()
parser.source_database = DdlParse.DATABASE.postgresql
parser.ddl = test_ddl
table = parser.parse()
table.columns

character varying seems to be handled by regex at ddlparse/ddlparse.py: 202 but I did not yet find the issue.

I'll submit a PR if I find the issue, but not yet. Thank you