Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

psqldef panics on valid VIEW with nested CASE #455

Open
chumaltd opened this issue Oct 27, 2023 · 1 comment
Open

psqldef panics on valid VIEW with nested CASE #455

chumaltd opened this issue Oct 27, 2023 · 1 comment
Labels
psqldef Bugs or feature requests related to PostgreSQL

Comments

@chumaltd
Copy link
Contributor

psqldef gets panic on parsing online VIEWs with nested CASE.
This is split from #454, as they have different causes.

Platform

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

--export output

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

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0xbf86e9]

goroutine 1 [running]:
github.com/k0kubun/sqldef/database/postgres.PostgresParser.parseExpr({{0x0?}, 0x0?}, 0x0?)
        /home/runner/work/sqldef/sqldef/database/postgres/parser.go:293 +0x29
github.com/k0kubun/sqldef/database/postgres.PostgresParser.parseExpr({{0x0?}, 0x0?}, 0x0?)
        /home/runner/work/sqldef/sqldef/database/postgres/parser.go:351 +0xbe6
github.com/k0kubun/sqldef/database/postgres.PostgresParser.parseResTarget({{0x203000?}, 0x0?}, 0xc0000c23c0)
        /home/runner/work/sqldef/sqldef/database/postgres/parser.go:281 +0x23b
github.com/k0kubun/sqldef/database/postgres.PostgresParser.parseSelectStmt({{0x0?}, 0x0?}, 0xc000141b80)
        /home/runner/work/sqldef/sqldef/database/postgres/parser.go:201 +0x1f6
github.com/k0kubun/sqldef/database/postgres.PostgresParser.parseViewStmt({{0x1?}, 0x68?}, 0xc000303f00)
        /home/runner/work/sqldef/sqldef/database/postgres/parser.go:172 +0xaf
github.com/k0kubun/sqldef/database/postgres.PostgresParser.parseStmt({{0xc00040527f?}, 0x0?}, 0xc0003d0fa0?)
        /home/runner/work/sqldef/sqldef/database/postgres/parser.go:76 +0x185
github.com/k0kubun/sqldef/database/postgres.PostgresParser.Parse({{0x2b?}, 0x40?}, {0xc000400000, 0x5498})
        /home/runner/work/sqldef/sqldef/database/postgres/parser.go:45 +0x195
github.com/k0kubun/sqldef/schema.ParseDDLs(0x203000?, {0x410700?, 0xc000129280?}, {0xc000400000?, 0xf4240?}, {0xc00003a600, 0x6})
        /home/runner/work/sqldef/sqldef/schema/parser.go:464 +0x62
github.com/k0kubun/sqldef.Run(0x1, {0x412e18, 0xc00027c360}, {0x410700, 0xc000129280}, 0xc000197730)
        /home/runner/work/sqldef/sqldef/sqldef.go:44 +0x152
main.main()
        /home/runner/work/sqldef/sqldef/cmd/psqldef/psqldef.go:148 +0x3f3

Input SQL

This is a reproducible DDL.

CREATE VIEW nested_case AS
  SELECT CASE
    WHEN 1 > 6 THEN 3
    ELSE CASE 4 + 1
      WHEN 1 THEN 1
      ELSE NULL
    END
END AS value;
@chumaltd
Copy link
Contributor Author

With MATERIALIZED VIEW, psqldef doesn't panics, but puts syntax error.
This behavior looks almost OK, but just have quoting issue.

--export output

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

2023/10/28 11:32:38 found syntax error when parsing DDL "CREATE MATERIALIZED VIEW public.nested_case AS SELECT CASE WHEN (1 > 6) THEN 3 ELSE CASE (4 + 1) WHEN 1 THEN 1 ELSE NULL::integer END END AS value": syntax error at position 147 near 'value'

Input SQL

CREATE MATERIALIZED VIEW nested_case AS
  SELECT CASE
    WHEN 1 > 6 THEN 3
    ELSE CASE 4 + 1
      WHEN 1 THEN 1
      ELSE NULL
    END
END AS value;

@k0kubun k0kubun added the psqldef Bugs or feature requests related to PostgreSQL label Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
psqldef Bugs or feature requests related to PostgreSQL
Projects
None yet
Development

No branches or pull requests

2 participants