markdrago / pgsanity

Check syntax of postgresql sql files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pgsanity reports error when .sql file is preceded with CREATE syntax

felikjunvianto opened this issue · comments

Just tried to verify the sanity of below sql files

BEGIN

CREATE SCHEMA transactional;

CREATE TABLE transactional.passenger (
  --primary key
  passenger_type_id      SERIAL,

  --datas
  passenger_type_name    VARCHAR, 
  is_active              BOOLEAN,
  additional_data        JSONB,

  --metadata
  sys_update_description VARCHAR,
  sys_update_timestamp   TIMESTAMPTZ,
  sys_update_name        VARCHAR,
  sys_creation_name      VARCHAR DEFAULT 'CIMAHI',
  sys_creation_timestamp TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,

  PRIMARY KEY (passenger_type_id),
  UNIQUE (passenger_type_name)
);

-- other create table, omitted for succinctness

COMMIT;

And below is the result from pgsanity: line 3: ERROR: syntax error at or near "CREATE". After commenting line 3, the file passed the verification (even without commenting the last COMMIT; line).

Is there an issue? I am using Python 2.7.6.

Many thanks.

I am sorry the error was on my side. Apparently I forgot to close the BEGIN statement with semicolon.

After add the required semicolon, the pgsanity check run smoothly.

No worries. The error messages are one of the downsides of pgsanity/ecpg. If it said, "missing semicolon on line 1" you probably would have found the issue immediately.