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

feat(postgresql): Add support for PostgreSQL multi-dimensional arrays #2338

Merged
merged 44 commits into from
Jul 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
c33cb8e
feat: pg multi dim arrays
colli173 May 30, 2022
4630b30
add e2e test
colli173 May 30, 2022
e80ace6
update array dims on table alter
colli173 May 30, 2022
a9aa0f9
remove accidental insert statement
colli173 May 30, 2022
cdaa60c
Merge branch 'main' of https://github.com/colli173/sqlc into feature/…
colli173 Jul 2, 2022
9e78e66
Merge branch 'main' of https://github.com/kyleconroy/sqlc into featur…
colli173 Jul 2, 2022
4e389d1
Merge branch 'main' of https://github.com/kyleconroy/sqlc into featur…
colli173 Aug 4, 2022
2000d6d
Merge branch 'main' of https://github.com/kyleconroy/sqlc into featur…
colli173 Aug 12, 2022
a007b7f
Merge branch 'main' of https://github.com/kyleconroy/sqlc into featur…
colli173 Aug 27, 2022
f5d1ad9
Merge branch 'main' of https://github.com/kyleconroy/sqlc into featur…
colli173 Sep 2, 2022
5cc5c5f
regenerate to fix mismatch in testdata generated code version
colli173 Sep 3, 2022
1b954c3
regenerate codegen json
colli173 Sep 3, 2022
a3bc887
fix merge conflicts
colli173 Feb 14, 2023
ddc0b2a
madd check for pgxv4 driver in go type
colli173 Feb 14, 2023
cb169fb
initial attempt at pgtype.Array vs pgtype.FlatArray
colli173 Feb 14, 2023
b8b0bc5
Merge branch 'main' of https://github.com/kyleconroy/sqlc into featur…
colli173 Feb 16, 2023
21e5c0b
use pgxtypes flatarray and array
colli173 Feb 16, 2023
0ff26c0
Merge branch 'main' of https://github.com/kyleconroy/sqlc into featur…
colli173 Feb 23, 2023
f2b511a
busing same approach with non-pgx types as pull/2090
colli173 Feb 23, 2023
1a62698
remove newline
colli173 Feb 23, 2023
6f2e193
Merge branch 'main' of https://github.com/kyleconroy/sqlc into featur…
colli173 Feb 27, 2023
ceb0626
Merge branch 'main' of https://github.com/kyleconroy/sqlc into featur…
colli173 Mar 1, 2023
84eda98
Merge branch 'main' of https://github.com/kyleconroy/sqlc into featur…
colli173 Mar 7, 2023
1ac031e
fix merge conflicts
colli173 Apr 13, 2023
fc5ef8e
Merge branch 'main' of https://github.com/kyleconroy/sqlc into featur…
colli173 Apr 20, 2023
8ed8493
Merge branch 'main' of https://github.com/kyleconroy/sqlc into featur…
colli173 Apr 21, 2023
7adb257
Merge branch 'main' of https://github.com/kyleconroy/sqlc into featur…
colli173 Apr 24, 2023
a5a66e3
Merge branch 'main' of https://github.com/kyleconroy/sqlc into featur…
colli173 May 1, 2023
dbf287e
Merge branch 'main' into fork-colli173-feature/pg-multi-dim-arrays
kyleconroy Jun 7, 2023
be4a324
Regenerate proto files
kyleconroy Jun 7, 2023
73f38c8
Merge branch 'main' of https://github.com/kyleconroy/sqlc into featur…
colli173 Jun 12, 2023
da615a2
fixes
colli173 Jun 12, 2023
ab7d6fd
fixes, proto regen
colli173 Jun 12, 2023
52ac9e5
Merge branch 'main' of https://github.com/kyleconroy/sqlc into colli1…
colli173 Jun 18, 2023
6195e8d
Merge branch 'main' of https://github.com/kyleconroy/sqlc into featur…
colli173 Jun 18, 2023
e6d3e06
Merge branch 'main' into colli173/feature-pg-multi-dim-arrays
colli173 Jul 30, 2023
e27fbd3
make regen
colli173 Jul 30, 2023
4745b7e
Merge branch 'colli173/feature-pg-multi-dim-arrays' into feature/pg-m…
colli173 Jul 30, 2023
71dfb83
skip change for non-postgres engines
colli173 Jul 30, 2023
76e0f4d
fix(endtoend): update process_plugin_disabled stderr.txt to match main
andrewmbenton Jul 30, 2023
e824556
Update new column type parameter name to ArrayDims from ArrayBounds
andrewmbenton Jul 30, 2023
8e71346
Fix a subtle bug treating arrays and sqlc.slice "columns" identically
andrewmbenton Jul 30, 2023
eaf3761
Merge branch 'main' into feature/pg-multi-dim-arrays
andrewmbenton Jul 30, 2023
3bae387
An extra nil pointer check
andrewmbenton Jul 30, 2023
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
12 changes: 7 additions & 5 deletions internal/cmd/shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,12 @@ func pluginCatalog(c *catalog.Catalog) *plugin.Catalog {
Schema: c.Type.Schema,
Name: c.Type.Name,
},
Comment: c.Comment,
NotNull: c.IsNotNull,
Unsigned: c.IsUnsigned,
IsArray: c.IsArray,
Length: int32(l),
Comment: c.Comment,
NotNull: c.IsNotNull,
Unsigned: c.IsUnsigned,
IsArray: c.IsArray,
ArrayDims: int32(c.ArrayDims),
Length: int32(l),
Table: &plugin.Identifier{
Catalog: t.Rel.Catalog,
Schema: t.Rel.Schema,
Expand Down Expand Up @@ -252,6 +253,7 @@ func pluginQueryColumn(c *compiler.Column) *plugin.Column {
NotNull: c.NotNull,
Unsigned: c.Unsigned,
IsArray: c.IsArray,
ArrayDims: int32(c.ArrayDims),
Length: int32(l),
IsNamedParam: c.IsNamedParam,
IsFuncCall: c.IsFuncCall,
Expand Down
7 changes: 6 additions & 1 deletion internal/codegen/golang/go_type.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package golang

import (
"strings"

"github.com/sqlc-dev/sqlc/internal/codegen/sdk"
"github.com/sqlc-dev/sqlc/internal/plugin"
)
Expand Down Expand Up @@ -48,9 +50,12 @@ func goType(req *plugin.CodeGenRequest, col *plugin.Column) string {
}
}
typ := goInnerType(req, col)
if col.IsArray || col.IsSqlcSlice {
if col.IsSqlcSlice {
return "[]" + typ
}
if col.IsArray {
return strings.Repeat("[]", int(col.ArrayDims)) + typ
}
return typ
}

Expand Down
3 changes: 3 additions & 0 deletions internal/compiler/output_columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func (c *Compiler) OutputColumns(stmt ast.Node) ([]*catalog.Column, error) {
IsNotNull: col.NotNull,
IsUnsigned: col.Unsigned,
IsArray: col.IsArray,
ArrayDims: col.ArrayDims,
Comment: col.Comment,
Length: col.Length,
})
Expand Down Expand Up @@ -289,6 +290,7 @@ func (c *Compiler) outputColumns(qc *QueryCatalog, node ast.Node) ([]*Column, er
NotNull: c.NotNull,
Unsigned: c.Unsigned,
IsArray: c.IsArray,
ArrayDims: c.ArrayDims,
Length: c.Length,
})
}
Expand Down Expand Up @@ -626,6 +628,7 @@ func outputColumnRefs(res *ast.ResTarget, tables []*Table, node *ast.ColumnRef)
NotNull: c.NotNull,
Unsigned: c.Unsigned,
IsArray: c.IsArray,
ArrayDims: c.ArrayDims,
Length: c.Length,
EmbedTable: c.EmbedTable,
OriginalName: c.Name,
Expand Down
1 change: 1 addition & 0 deletions internal/compiler/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Column struct {
NotNull bool
Unsigned bool
IsArray bool
ArrayDims int
Comment string
Length *int
IsNamedParam bool
Expand Down
17 changes: 9 additions & 8 deletions internal/compiler/query_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ func (comp *Compiler) buildQueryCatalog(c *catalog.Catalog, node ast.Node, embed

func ConvertColumn(rel *ast.TableName, c *catalog.Column) *Column {
return &Column{
Table: rel,
Name: c.Name,
DataType: dataType(&c.Type),
NotNull: c.IsNotNull,
Unsigned: c.IsUnsigned,
IsArray: c.IsArray,
Type: &c.Type,
Length: c.Length,
Table: rel,
Name: c.Name,
DataType: dataType(&c.Type),
NotNull: c.IsNotNull,
Unsigned: c.IsUnsigned,
IsArray: c.IsArray,
ArrayDims: c.ArrayDims,
Type: &c.Type,
Length: c.Length,
}
}

Expand Down
4 changes: 4 additions & 0 deletions internal/compiler/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ func (comp *Compiler) resolveCatalogRefs(qc *QueryCatalog, rvs []*ast.RangeVar,
NotNull: p.NotNull(),
Unsigned: c.IsUnsigned,
IsArray: c.IsArray,
ArrayDims: c.ArrayDims,
Length: c.Length,
Table: table,
IsNamedParam: isNamed,
Expand Down Expand Up @@ -283,6 +284,7 @@ func (comp *Compiler) resolveCatalogRefs(qc *QueryCatalog, rvs []*ast.RangeVar,
NotNull: p.NotNull(),
Unsigned: c.IsUnsigned,
IsArray: c.IsArray,
ArrayDims: c.ArrayDims,
Table: table,
IsNamedParam: isNamed,
IsSqlcSlice: p.IsSqlcSlice(),
Expand Down Expand Up @@ -459,6 +461,7 @@ func (comp *Compiler) resolveCatalogRefs(qc *QueryCatalog, rvs []*ast.RangeVar,
NotNull: p.NotNull(),
Unsigned: c.IsUnsigned,
IsArray: c.IsArray,
ArrayDims: c.ArrayDims,
Table: &ast.TableName{Schema: schema, Name: rel},
Length: c.Length,
IsNamedParam: isNamed,
Expand Down Expand Up @@ -569,6 +572,7 @@ func (comp *Compiler) resolveCatalogRefs(qc *QueryCatalog, rvs []*ast.RangeVar,
NotNull: c.IsNotNull,
Unsigned: c.IsUnsigned,
IsArray: c.IsArray,
ArrayDims: c.ArrayDims,
Table: table,
IsNamedParam: isNamed,
IsSqlcSlice: p.IsSqlcSlice(),
Expand Down
16 changes: 12 additions & 4 deletions internal/compiler/to_column.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ func isArray(n *ast.TypeName) bool {
return len(n.ArrayBounds.Items) > 0
}

func arrayDims(n *ast.TypeName) int {
if n == nil || n.ArrayBounds == nil {
return 0
}
return len(n.ArrayBounds.Items)
}

func toColumn(n *ast.TypeName) *Column {
if n == nil {
panic("can't build column for nil type name")
Expand All @@ -23,9 +30,10 @@ func toColumn(n *ast.TypeName) *Column {
panic("toColumn: " + err.Error())
}
return &Column{
Type: typ,
DataType: strings.TrimPrefix(astutils.Join(n.Names, "."), "."),
NotNull: true, // XXX: How do we know if this should be null?
IsArray: isArray(n),
Type: typ,
DataType: strings.TrimPrefix(astutils.Join(n.Names, "."), "."),
NotNull: true, // XXX: How do we know if this should be null?
IsArray: isArray(n),
ArrayDims: arrayDims(n),
}
}
Loading