Skip to content
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
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,19 @@ require (
github.com/jinzhu/inflection v1.0.0
github.com/lib/pq v1.12.3
github.com/ncruces/go-sqlite3 v0.35.3
github.com/pganalyze/pg_query_go/v6 v6.2.2
github.com/riza-io/grpc-go v0.2.0
github.com/spf13/cobra v1.10.2
github.com/spf13/pflag v1.0.10
github.com/sqlc-dev/doubleclick v1.0.0
github.com/sqlc-dev/marino v0.1.0
github.com/sqlc-dev/meyer v0.1.1
github.com/sqlc-dev/oliphant v0.1.0
github.com/sqlc-dev/zetajones v0.1.0
github.com/tetratelabs/wazero v1.12.0
github.com/wasilibs/go-pgquery v0.0.0-20250409022910-10ac41983c07
github.com/xeipuuv/gojsonschema v1.2.0
golang.org/x/sync v0.22.0
google.golang.org/grpc v1.83.0
google.golang.org/protobuf v1.36.11
google.golang.org/protobuf v1.36.12
gopkg.in/yaml.v3 v3.0.1
)

Expand All @@ -44,7 +43,6 @@ require (
github.com/ncruces/go-sqlite3-wasm/v3 v3.2.35304 // indirect
github.com/ncruces/julianday v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
Expand Down
12 changes: 4 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ github.com/ncruces/go-sqlite3-wasm/v3 v3.2.35304 h1:5NoQAewtgKNK3G4bjNPxVoGXu6F6
github.com/ncruces/go-sqlite3-wasm/v3 v3.2.35304/go.mod h1:o8gr9w/50fXA5TDskg6bNUjvqmFfw4KaXth4q+yDSjg=
github.com/ncruces/julianday v1.0.0 h1:fH0OKwa7NWvniGQtxdJRxAgkBMolni2BjDHaWTxqt7M=
github.com/ncruces/julianday v1.0.0/go.mod h1:Dusn2KvZrrovOMJuOt0TNXL6tB7U2E8kvza5fFc9G7g=
github.com/pganalyze/pg_query_go/v6 v6.2.2 h1:O0L6zMC226R82RF3X5n0Ki6HjytDsoAzuzp4ATVAHNo=
github.com/pganalyze/pg_query_go/v6 v6.2.2/go.mod h1:Cn6+j4870kJz3iYNsb0VsNG04vpSWgEvBwc590J4qD0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/riza-io/grpc-go v0.2.0 h1:2HxQKFVE7VuYstcJ8zqpN84VnAoJ4dCL6YFhJewNcHQ=
Expand All @@ -73,6 +71,8 @@ github.com/sqlc-dev/marino v0.1.0 h1:8Fn13vFhx7OUcmDFfRZdf3zARAbNl04Lcy74211ZpIw
github.com/sqlc-dev/marino v0.1.0/go.mod h1:mQxC2dgDE0DWHMb2B5jZNk7KToJuS6wnxnffBfYnq08=
github.com/sqlc-dev/meyer v0.1.1 h1:BAeZcfgLyTnk9f90DyGEKXPrHxtgvVD/DTM6awq2kUY=
github.com/sqlc-dev/meyer v0.1.1/go.mod h1:pS4USCRf/SLjWtaMcnTo4YrEEFKBj8CyyqlxcVUJQH8=
github.com/sqlc-dev/oliphant v0.1.0 h1:RAsO6BMitIzB2+swx/qzUR5nf6w4cQ1abgHIu+Fgppo=
github.com/sqlc-dev/oliphant v0.1.0/go.mod h1:fRM/t4FutRddTIq2YCuS4O9o+2rRwSwELRvLMqtPloo=
github.com/sqlc-dev/zetajones v0.1.0 h1:VeG0atx6lNABr9V2bSI5vL9DvOKTHX0XjMqWUE/rv40=
github.com/sqlc-dev/zetajones v0.1.0/go.mod h1:dU1DxwqC6Cahbpnw16KpH1J2waWRDMdwyDSvovMZR4I=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand All @@ -82,10 +82,6 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/tetratelabs/wazero v1.12.0 h1:DuWcpNu/FzgEXgGBDp8J1Spc+CWOvvtvVyjKlaZopYU=
github.com/tetratelabs/wazero v1.12.0/go.mod h1:LvKtzl2RqO4gyF27BiXU+nKAjcV8f38U+kP/q2vgxh0=
github.com/wasilibs/go-pgquery v0.0.0-20250409022910-10ac41983c07 h1:mJdDDPblDfPe7z7go8Dvv1AJQDI3eQ/5xith3q2mFlo=
github.com/wasilibs/go-pgquery v0.0.0-20250409022910-10ac41983c07/go.mod h1:Ak17IJ037caFp4jpCw/iQQ7/W74Sqpb1YuKJU6HTKfM=
github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52 h1:OvLBa8SqJnZ6P+mjlzc2K7PM22rRUPE1x32G9DTPrC4=
github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52/go.mod h1:jMeV4Vpbi8osrE/pKUxRZkVaA0EX7NZN0A9/oRzgpgY=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0=
Expand Down Expand Up @@ -124,8 +120,8 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa h1:
google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8=
google.golang.org/grpc v1.83.0 h1:JeNZEKJFbQxArAMl+hiytHauacDNqJUllNfmIMmpqnQ=
google.golang.org/grpc v1.83.0/go.mod h1:kDyl6SKsiHKt0uylY5gtn5cEjkrIOhQOGDgIc4JGwzQ=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc=
google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
16 changes: 10 additions & 6 deletions internal/engine/postgresql/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package postgresql
import (
"fmt"

pg "github.com/pganalyze/pg_query_go/v6"
pg "github.com/sqlc-dev/oliphant"

"github.com/sqlc-dev/sqlc/internal/sql/ast"
)
Expand Down Expand Up @@ -1424,7 +1424,7 @@ func convertDeleteStmt(n *pg.DeleteStmt) *ast.DeleteStmt {
},
UsingClause: convertSlice(n.UsingClause),
WhereClause: convertNode(n.WhereClause),
ReturningList: convertSlice(n.ReturningList),
ReturningList: convertSlice(n.ReturningClause.GetExprs()),
WithClause: convertWithClause(n.WithClause),
}
}
Expand Down Expand Up @@ -1806,7 +1806,7 @@ func convertInsertStmt(n *pg.InsertStmt) *ast.InsertStmt {
Cols: convertSlice(n.Cols),
SelectStmt: convertNode(n.SelectStmt),
OnConflictClause: convertOnConflictClause(n.OnConflictClause),
ReturningList: convertSlice(n.ReturningList),
ReturningList: convertSlice(n.ReturningClause.GetExprs()),
WithClause: convertWithClause(n.WithClause),
Override: ast.OverridingKind(n.Override),
}
Expand All @@ -1825,13 +1825,17 @@ func convertIntoClause(n *pg.IntoClause) *ast.IntoClause {
if n == nil {
return nil
}
var viewQuery ast.Node = &ast.TODO{}
if n.ViewQuery != nil {
viewQuery = convertQuery(n.ViewQuery)
}
return &ast.IntoClause{
Rel: convertRangeVar(n.Rel),
ColNames: convertSlice(n.ColNames),
Options: convertSlice(n.Options),
OnCommit: ast.OnCommitAction(n.OnCommit),
TableSpaceName: makeString(n.TableSpaceName),
ViewQuery: convertNode(n.ViewQuery),
ViewQuery: viewQuery,
SkipData: n.SkipData,
}
}
Expand Down Expand Up @@ -2434,7 +2438,7 @@ func convertRowCompareExpr(n *pg.RowCompareExpr) *ast.RowCompareExpr {
}
return &ast.RowCompareExpr{
Xpr: convertNode(n.Xpr),
Rctype: ast.RowCompareType(n.Rctype),
Rctype: ast.RowCompareType(n.Cmptype),
Opnos: convertSlice(n.Opnos),
Opfamilies: convertSlice(n.Opfamilies),
Inputcollids: convertSlice(n.Inputcollids),
Expand Down Expand Up @@ -2808,7 +2812,7 @@ func convertUpdateStmt(n *pg.UpdateStmt) *ast.UpdateStmt {
TargetList: convertSlice(n.TargetList),
WhereClause: convertNode(n.WhereClause),
FromClause: convertSlice(n.FromClause),
ReturningList: convertSlice(n.ReturningList),
ReturningList: convertSlice(n.ReturningClause.GetExprs()),
WithClause: convertWithClause(n.WithClause),
}
}
Expand Down
34 changes: 30 additions & 4 deletions internal/engine/postgresql/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import (
"io"
"strings"

nodes "github.com/pganalyze/pg_query_go/v6"
nodes "github.com/sqlc-dev/oliphant"
"github.com/sqlc-dev/oliphant/parser"

"github.com/sqlc-dev/sqlc/internal/engine/postgresql/parser"
"github.com/sqlc-dev/sqlc/internal/source"
"github.com/sqlc-dev/sqlc/internal/sql/ast"
"github.com/sqlc-dev/sqlc/internal/sql/sqlerr"
)

var Parse = nodes.Parse
var Fingerprint = nodes.Fingerprint

func stringSlice(list *nodes.List) []string {
items := []string{}
for _, item := range list.Items {
Expand Down Expand Up @@ -158,7 +161,30 @@ func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) {
}

var stmts []ast.Statement
// PostgreSQL 18 changed stmt_location to point at the statement's first
// token. The rest of the compiler expects the earlier convention, where a
// statement begins where the previous one ended and so carries its leading
// comments (that's where `-- name:` lives).
loc := 0
for _, raw := range tree.Stmts {
start := loc
end := int(raw.StmtLocation) + int(raw.StmtLen)
next := end
for next < len(contents) && contents[next] != ';' {
next++
}
terminated := next < len(contents)
if terminated {
next++
}
loc = next
length := end - start
if !terminated {
// A zero length marked an unterminated final statement before
// PostgreSQL 18, and the compiler still reports it that way.
length = 0
}

n, err := translate(raw.Stmt)
if err == errSkip {
continue
Expand All @@ -172,8 +198,8 @@ func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) {
stmts = append(stmts, ast.Statement{
Raw: &ast.RawStmt{
Stmt: n,
StmtLocation: int(raw.StmtLocation),
StmtLen: int(raw.StmtLen),
StmtLocation: start,
StmtLen: length,
},
})
}
Expand Down
10 changes: 0 additions & 10 deletions internal/engine/postgresql/parse_default.go

This file was deleted.

10 changes: 0 additions & 10 deletions internal/engine/postgresql/parse_wasi.go

This file was deleted.

7 changes: 0 additions & 7 deletions internal/engine/postgresql/parser/parser_default.go

This file was deleted.

7 changes: 0 additions & 7 deletions internal/engine/postgresql/parser/parser_wasi.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/engine/postgresql/utils.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package postgresql

import (
nodes "github.com/pganalyze/pg_query_go/v6"
nodes "github.com/sqlc-dev/oliphant"
)

func isArray(n *nodes.TypeName) bool {
Expand Down
Loading