Skip to content

engine/postgres: Upgrade to pg_query_go/v4 #2114

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

Merged
merged 8 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/jinzhu/inflection v1.0.0
github.com/lib/pq v1.10.7
github.com/mattn/go-sqlite3 v1.14.16
github.com/pganalyze/pg_query_go/v2 v2.2.0
github.com/pganalyze/pg_query_go/v4 v4.2.0
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
golang.org/x/sync v0.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/pganalyze/pg_query_go/v2 v2.2.0 h1:OW+reH+ZY7jdEuPyuLGlf1m7dLbE+fDudKXhLs0Ttpk=
github.com/pganalyze/pg_query_go/v2 v2.2.0/go.mod h1:XAxmVqz1tEGqizcQ3YSdN90vCOHBWjJi8URL1er5+cA=
github.com/pganalyze/pg_query_go/v4 v4.2.0 h1:67hSBZXYfABNYisEu/Xfu6R2gupnQwaoRhQicy0HSnQ=
github.com/pganalyze/pg_query_go/v4 v4.2.0/go.mod h1:aEkDNOXNM5j0YGzaAapwJ7LB3dLNj+bvbWcLv1hOVqA=
github.com/pingcap/errors v0.11.0/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
github.com/pingcap/errors v0.11.5-0.20210425183316-da1aaba5fb63 h1:+FZIDR/D97YOPik4N4lPDaUcLDF/EQPogxtlHB2ZZRM=
github.com/pingcap/errors v0.11.5-0.20210425183316-da1aaba5fb63/go.mod h1:X2r9ueLEUZgtx2cIogM0v4Zj5uvvzhuuiu7Pn8HzMPg=
Expand Down
5 changes: 5 additions & 0 deletions internal/compiler/compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ type Relation struct {
func parseRelation(node ast.Node) (*Relation, error) {
switch n := node.(type) {

case *ast.Boolean:
return &Relation{
Name: "bool",
}, nil

case *ast.List:
parts := stringSlice(n)
switch len(parts) {
Expand Down
6 changes: 6 additions & 0 deletions internal/compiler/output_columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ func outputColumns(qc *QueryCatalog, node ast.Node) ([]*Column, error) {
col := toColumn(tc.TypeName)
col.Name = name
cols = append(cols, col)
} else if aconst, ok := n.Defresult.(*ast.A_Const); ok {
tn, err := ParseTypeName(aconst.Val)
if err != nil {
return nil, err
}
cols = append(cols, &Column{Name: name, DataType: dataType(tn), NotNull: true})
} else {
cols = append(cols, &Column{Name: name, DataType: "any", NotNull: false})
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ ON CONFLICT DO NOTHING
RETURNING *;

-- name: GetOne :one
SELECT * FROM foo WHERE a = ? AND b = ? LIMIT 1;
SELECT * FROM foo WHERE a = $1 AND b = $2 LIMIT 1;

-- name: GetAll :many
SELECT * FROM foo;

-- name: GetAllAByB :many
SELECT a FROM foo WHERE b = ?;
SELECT a FROM foo WHERE b = $1;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ ON CONFLICT DO NOTHING
RETURNING *;

-- name: GetOne :one
SELECT * FROM foo WHERE a = ? AND b = ? LIMIT 1;
SELECT * FROM foo WHERE a = $1 AND b = $2 LIMIT 1;

-- name: GetAll :many
SELECT * FROM foo;

-- name: GetAllAByB :many
SELECT a FROM foo WHERE b = ?;
SELECT a FROM foo WHERE b = $1;
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
SELECT random(1);
SELECT position();
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# package querytest
query.sql:1:8: function random(unknown) does not exist
query.sql:2:8: function position() does not exist
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
SELECT random(1);
SELECT position();
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# package querytest
query.sql:1:8: function random(unknown) does not exist
query.sql:2:8: function position() does not exist
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
SELECT random(1);
SELECT position();
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# package querytest
query.sql:1:8: function random(unknown) does not exist
query.sql:2:8: function position() does not exist

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,3 @@ SELECT count(1) FROM bar WHERE id = $1 AND name <> sqlc.arg(name);

-- name: CountThree :one
SELECT count(1) FROM bar WHERE id > $2 AND phone <> sqlc.arg(phone) AND name <> $1;

-- name: CountFour :one
SELECT count(1) FROM bar WHERE id > ? AND phone <> sqlc.arg(phone) AND name <> ?;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CREATE TABLE users (
);

-- name: FindByID :many
SELECT * FROM users WHERE ? = id;
SELECT * FROM users WHERE $1 = id;

-- name: FindByIDAndName :many
SELECT * FROM users WHERE ? = id AND ? = name;
SELECT * FROM users WHERE $1 = id AND $1 = name;
Loading