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] Cannot parse t.* in select t.* from t; #397

Closed
halwhite opened this issue May 9, 2023 · 4 comments
Closed

[psqldef] Cannot parse t.* in select t.* from t; #397

halwhite opened this issue May 9, 2023 · 4 comments

Comments

@halwhite
Copy link

halwhite commented May 9, 2023

Platform

In version 0.11.50 (that we are using now), Input SQL is loaded correctly, but in version 0.15.24, an error occurs when loading.

  • OS: macOS
  • RDBMS: PostgreSQL
  • Version: 0.15.24

--export output

-- No table exists --

Input SQL

CREATE TABLE
  users (
    usre_id INT PRIMARY KEY,
    name VARCHAR(100) NOT NULL
  );

CREATE VIEW
  users_view AS
SELECT
  u.*
FROM
  users AS u;

Current output

panic: interface conversion: pg_query.isNode_Node is *pg_query.Node_AStar, not *pg_query.Node_String_

goroutine 1 [running]:
github.com/k0kubun/sqldef/database/postgres.PostgresParser.parseExpr({{0x0?}, 0x0?}, 0x0?)
        /home/runner/work/sqldef/sqldef/database/postgres/parser.go:330 +0x8c4
github.com/k0kubun/sqldef/database/postgres.PostgresParser.parseResTarget({{0x0?}, 0x0?}, 0x400009cba0)
        /home/runner/work/sqldef/sqldef/database/postgres/parser.go:231 +0x28
github.com/k0kubun/sqldef/database/postgres.PostgresParser.parseSelectStmt({{0x1?}, 0x0?}, 0x40001c0000)
        /home/runner/work/sqldef/sqldef/database/postgres/parser.go:198 +0x1a8
github.com/k0kubun/sqldef/database/postgres.PostgresParser.parseViewStmt({{0x20?}, 0x40?}, 0x40000f5f80)
        /home/runner/work/sqldef/sqldef/database/postgres/parser.go:169 +0x90
github.com/k0kubun/sqldef/database/postgres.PostgresParser.parseStmt({{0x40003160f7?}, 0x60?}, 0x40001d7701?)
        /home/runner/work/sqldef/sqldef/database/postgres/parser.go:76 +0x120
github.com/k0kubun/sqldef/database/postgres.PostgresParser.Parse({{0x200?}, 0x1?}, {0x40003160a0, 0x95})
        /home/runner/work/sqldef/sqldef/database/postgres/parser.go:45 +0x14c
github.com/k0kubun/sqldef/schema.ParseDDLs(0x0?, {0x40bf20?, 0x40001a8fb0?}, {0x40003160a0?, 0x40001d7928?}, {0x40001a93b0, 0x6})
        /home/runner/work/sqldef/sqldef/schema/parser.go:463 +0x48
github.com/k0kubun/sqldef/schema.GenerateIdempotentDDLs(0x1, {0x40bf20, 0x40001a8fb0}, {0x40003160a0?, 0x1000?}, {0x0, 0x0}, {{0x0, 0x0, 0x0}, ...}, ...)
        /home/runner/work/sqldef/sqldef/schema/generator.go:62 +0x64
github.com/k0kubun/sqldef.Run(0x1, {0x40e578, 0x40002fa360}, {0x40bf20, 0x40001a8fb0}, 0x400022d6c0)
        /home/runner/work/sqldef/sqldef/sqldef.go:60 +0x208
main.main()
        /home/runner/work/sqldef/sqldef/cmd/psqldef/psqldef.go:148 +0x2dc

Expected output

create view without panic

@k0kubun
Copy link
Collaborator

k0kubun commented May 9, 2023

Thank you for reporting it. Could you check which version between 0.11.50 and 0.15.24 introduced this problem?

@halwhite
Copy link
Author

by git bisect, e1bba65 introduced this problem.

@k0kubun
Copy link
Collaborator

k0kubun commented May 22, 2023

Thanks for finding it. I think, while the version before that revision happens to "work", it's not how it's supposed to parse the expression. So both versions seem broken in different ways.

The right solution to it is probably checking *pg_query.Node_AStar and using "*" for that type instead of field.Node.(*pgquery.Node_String_).String_.Str. Would you be interested in writing a pull request to fix it that way?

@hokaccha
Copy link
Collaborator

The bug crashing on select * has been fixed and this issue is closed. We know that other problems can occur, see this PR for more information. #423

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants