FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix parameter inference for aliased CTE columns by riordanpawley · Pull Request #4586 · sqlc-dev/sqlc · GitHub

/ sqlc Public
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .go  (5) .sql  (2) .yaml  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
          • db.go
          • models.go
          • query.sql.go
        • query.sql
        • schema.sql
        • sqlc.yaml
        • query.sql.go
28 changes: 26 additions & 2 deletions internal/compiler/resolve.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,26 @@ func (comp *Compiler) resolveCatalogRefs(qc *QueryCatalog, rvs []*ast.RangeVar,
}
return nil
}
indexQueryTable := func(table *Table) error {
columns := make([]*catalog.Column, 0, len(table.Columns))
for _, column := range table.Columns {
columnType := ast.TypeName{Name: column.DataType}
if column.Type != nil {
columnType = *column.Type
}
columns = append(columns, &catalog.Column{
Name: column.Name,
Type: columnType,
IsNotNull: column.NotNull,
IsUnsigned: column.Unsigned,
IsArray: column.IsArray,
ArrayDims: column.ArrayDims,
Comment: column.Comment,
Length: column.Length,
})
}
return indexTable(catalog.Table{Rel: table.Rel, Columns: columns})
}

for _, rv := range rvs {
if rv.Relname == nil {
Expand All @@ -66,8 +86,12 @@ func (comp *Compiler) resolveCatalogRefs(qc *QueryCatalog, rvs []*ast.RangeVar,
if qc == nil {
continue
}
// If the table name doesn't exist, first check if it's a CTE
if _, qcerr := qc.GetTable(fqn); qcerr != nil {
// If the table name doesn't exist, first check if it's a CTE.
queryTable, qcerr := qc.GetTable(fqn)
if qcerr != nil {
return nil, err
}
if err := indexQueryTable(queryTable); err != nil {
return nil, err
}
continue
Expand Down

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

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

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

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- name: CountRecentEvents :one
WITH activity AS (
SELECT happened_at AS activity_at
FROM events
)
SELECT COUNT(*) FILTER (WHERE activity_at >= $1)::bigint AS recent_events
FROM activity;
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE TABLE events (
happened_at timestamptz NOT NULL
);
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "2"
sql:
- engine: "postgresql"
schema: "schema.sql"
queries: "query.sql"
gen:
go:
package: "querytest"
out: "go"
sql_package: "pgx/v5"

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

Loading

Back | FazBrowse Home | New Git URL