sqldef / sqldef

Idempotent schema management for MySQL, PostgreSQL, and more

Home Page:https://sqldef.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

psqldef abort with syntax error on valid VIEW with any(ARRAY[])

chumaltd opened this issue · comments

Hi, I hit into 2 cases of psqldef parse error on VIEW.
And, I extracted reproducible DDL for each one. They may look meaningless, but taken from actual use cases.

1 case is split into #455, as they have different causes.

I think --skip-view option would be helpful for an escape hatch, as table operation looks much stable and Views can be CREATE OR REPLACEed by psql.

Platform

  • OS: Linux
  • RDBMS: PostgreSQL
  • Version: v0.16.9

Syntax error on any(ARRAY[])

This issue describes a syntax error VIEW while it's valid for PostgreSQL.

--export output

$ psqldef -Upostgres -hlocalhost -p5432 --export some_db

2023/10/23 12:50:14 found syntax error when parsing DDL "CREATE VIEW public.any_array AS SELECT 1 AS "?column?" WHERE (1 = ANY (ARRAY[1, 4, 5]))": syntax error at position 79 near '1'

Input SQL

CREATE VIEW any_array AS SELECT 1 WHERE 1 in (1, 4, 5);

PostgreSQL internally transforms this as follows:

CREATE VIEW any_array AS SELECT 1 WHERE 1 = ANY(ARRAY[1, 4, 5]);

I hit into 2 cases of psqldef parse error on VIEW.

Thank you for reporting them. I think both of them are described well. Could you, however, split an issue for these two different cases? They are fairly independent problems, so it'd be useful if they have different issue numbers.

I think --skip-view option would be helpful for an escape hatch

Sure. I'm open to adding one to psqldef while it's currently limited to mysqldef. Would you be interested in filing a pull request to add that to psqldef?

@k0kubun Thank you for your confirmation.
Yes, they should have different causes, and I just split into each issue.

Sure. I'm open to adding one to psqldef while it's currently limited to mysqldef. Would you be interested in filing a pull request to add that to psqldef?

It's nice to hear that.
Actually I haven't written a line of golang, but I'll just try for the next several days.
I feel much potential with --skip-view option.

MATERIALIZED VIEW gets the same behavior as VIEW.

--export output

$ psqldef -Upostgres -hlocalhost -p5432 --export some_db

2023/10/28 11:30:44 found syntax error when parsing DDL "CREATE MATERIALIZED VIEW public.any_array AS SELECT 1 AS "?column?" WHERE (1 = ANY (ARRAY[1, 4, 5]))": syntax error at position 92 near '1'

Input SQL

CREATE MATERIALIZED VIEW any_array AS SELECT 1 WHERE 1 in (1, 4, 5);