From ccf10d56909168461923d72115d7e655de83a10e Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Fri, 18 Aug 2023 15:53:27 +0200 Subject: [PATCH] Add integer arrays --- setup.cfg | 2 +- src/procrusql/parser.py | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/setup.cfg b/setup.cfg index 1d15854..9cb86fa 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = ProcruSQL -version = 0.0.12 +version = 0.0.13 author = Peter J. Holzer author_email = hjp@hjp.at description = Make a database fit its description diff --git a/src/procrusql/parser.py b/src/procrusql/parser.py index 3b14a19..e964a2f 100755 --- a/src/procrusql/parser.py +++ b/src/procrusql/parser.py @@ -285,15 +285,19 @@ def parse_column_definition(ps): ps2 = ps.clone() ps2.ast = [] ps2.skip_whitespace_and_comments() - sqltypes = ( - "integer", "int", "serial", "bigint", - "boolean", - "text", "character varying", - "date", "timestamp with time zone", "timestamptz", - "time", - "inet", - "double precision", "float8", "real", "float4", - "json", "jsonb", + sqltypes = sorted( + ( + "integer", "int", "serial", "bigint", + "boolean", + "text", "character varying", + "date", "timestamp with time zone", "timestamptz", + "time", + "inet", + "double precision", "float8", "real", "float4", + "json", "jsonb", + r"integer\[\]", r"int\[\]", r"bigint\[\]", + ), + key=lambda x: -len(x) # longest match first ) pattern = "(" + "|".join(sqltypes) + ")" + r"([ \t]+(default .*|not null\b|primary key\b|unique\b|references \w+\b))*" m = ps2.match(pattern)