KonnexionsGmbH / sqlparse

LALR grammar based SQL Parser
Other
43 stars 15 forks source link

`CONSTRAINT` not supported in CREATE TABLE #137

Closed c-bik closed 6 years ago

c-bik commented 6 years ago
CREATE TABLE
    TPAC_UMJTT (
        cko VARCHAR2(4000),
        chs VARCHAR2(10),
        jpo VARCHAR2(4000),
        tsp DATE,
        ckt VARCHAR2(100),
        cvt VARCHAR2(10),
        cvl VARCHAR2(4000),
        jky VARCHAR2(100),
        rdi CHAR(1),
        hnt VARCHAR2(100),
        CONSTRAINT t_pk PRIMARY KEY (cko, chs, jpo)
    )
{parse_error,{"13: syntax error before: 'PRIMARY'",

[{'CREATE',1},{'TABLE',1},{'NAME',10,"TPAC_UMJTT"},{'(',2},{'NAME',3,"cko"},
{'NAME',8,"VARCHAR2"},{'(',3},{'INTNUM',3,"4000"},{')',3},{',',3},{'NAME',3,"chs"},
{'NAME',8,"VARCHAR2"},{'(',4},{'INTNUM',4,"10"},{')',4},{',',4},{'NAME',3,"jpo"},
{'NAME',8,"VARCHAR2"},{'(',5},{'INTNUM',5,"4000"},{')',5},{',',5},{'NAME',3,"tsp"},
{'NAME',4,"DATE"},{',',6},{'NAME',3,"ckt"},{'NAME',8,"VARCHAR2"},{'(',7},
{'INTNUM',7,"100"},{')',7},{',',7},{'NAME',3,"cvt"},{'NAME',8,"VARCHAR2"},
{'(',8},{'INTNUM',8,"10"},{')',8},{',',8},{'NAME',3,"cvl"},{'NAME',8,"VARCHAR2"},
{'(',9},{'INTNUM',9,"4000"},{')',9},{',',9},{'NAME',3,"jky"},{'NAME',8,"VARCHAR2"},
{'(',10},{'INTNUM',10,"100"},{')',10},{',',10},{'NAME',3,"rdi"},{'NAME',4,"CHAR"},
{'(',11},{'INTNUM',11,"1"},{')',11},{',',11},{'NAME',3,"hnt"},{'NAME',8,"VARCHAR2"},
{'(',12},{'INTNUM',12,"100"},{')',12},{',',12},{'NAME',10,"CONSTRAINT"},{'NAME',4,"t_pk"},
{'PRIMARY',13},{'KEY',13},{'(',13},{'NAME',3,"cko"},{',',13},{'NAME',3,"chs"},{',',13},
{'NAME',3,"jpo"},{')',13},{')',14},{';',14}]}}}}

[{sqlparse_fold,fold_state_common,4,[{file,"sqlparse/src/sqlparse_fold.erl"},{line,71}]},
{gen_adapter,sql_params,2,[{file,"dderl/src/gen_adapter.erl"},{line,86}]},
{gen_adapter,opt_bind_json_obj,2,[{file,"dderl/src/gen_adapter.erl"},{line,61}]},
{gen_adapter,process_cmd,6,[{file,"dderl/src/gen_adapter.erl"},{line,146}]},
{dderl_session,spawn_gen_process_call,7,[{file,"dderl/src/dderl_session.erl"},{line,643}]}]
walter-weinmann commented 6 years ago

SQL Table Constraints 12c.pdf

The current grammar definition does not contain any constraints (the keyword CONSTRAINT is not included in the grammar). The attached document shows the current CONSTRAINT definition in the Oracle CREATE TABLE statement. Please make a decision which parts should be included in sqlparse.

@stoch @c-bik

c-bik commented 6 years ago

Below are the railroad diagrams extracted from @walter-weinmann 's PDF (comment above) for ease of reference to discussion:

This issue is just an observation on current sqlparse support / coverage, please feel free to choose / prioritize betwwen optional paths among the rules to impelment based other projects' need. The projects I am looking at has no requirement for this as of now (workarounds exists). Perhaps a cosmetic need in DDErl.

@stoch please decide!

constraint::= image inline_constraint::= image out_of_line_constraint::= image inline_ref_constraint::= image out_of_line_ref_constraint::= image referances_clause::= image constraint_state::= image using_index_clause::= image index_properties::= image index_attributes::= image exceptions_clause::= image

stoch commented 6 years ago

@walter-weinmann Eventually, in a first step, we might want one way to create foreign keys and constraints as separate statements. In a second step, the convenience of having this inside the create table statement might be added. For now, these statements are not needed in IMEM. In DDerl for Oracle, the statements should work in spite of the missing parser support. If that is given, the issue can be put on hold until we have a real need.

walter-weinmann commented 6 years ago

The following would be a quick fix to the current problem:

image

c-bik commented 6 years ago

@walter-weinmann looks neat! How does the coverage look like?