Skip to content
Open
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
3 changes: 2 additions & 1 deletion internal/compiler/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ func (c *Compiler) expandStmt(qc *QueryCatalog, raw *ast.RawStmt, node ast.Node)
}
}
for _, t := range tables {
if scope != "" && scope != t.Rel.Name {
isOldNew := strings.EqualFold(scope, "old") || strings.EqualFold(scope, "new")
if scope != "" && !isOldNew && scope != t.Rel.Name {
continue
}
tableName := c.quoteIdent(t.Rel.Name)
Expand Down
7 changes: 5 additions & 2 deletions internal/compiler/output_columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package compiler
import (
"errors"
"fmt"
"strings"

"github.com/sqlc-dev/sqlc/internal/sql/ast"
"github.com/sqlc-dev/sqlc/internal/sql/astutils"
Expand Down Expand Up @@ -269,7 +270,8 @@ func (c *Compiler) outputColumns(qc *QueryCatalog, node ast.Node) ([]*Column, er
// TODO: This code is copied in func expand()
for _, t := range tables {
scope := astutils.Join(n.Fields, ".")
if scope != "" && scope != t.Rel.Name {
isOldNew := strings.EqualFold(scope, "old") || strings.EqualFold(scope, "new")
if scope != "" && !isOldNew && scope != t.Rel.Name {
continue
}
for _, c := range t.Columns {
Expand Down Expand Up @@ -669,7 +671,8 @@ func outputColumnRefs(res *ast.ResTarget, tables []*Table, node *ast.ColumnRef)
if schema != "" && t.Rel.Schema != schema {
continue
}
if alias != "" && t.Rel.Name != alias {
isOldNew := strings.EqualFold(alias, "old") || strings.EqualFold(alias, "new")
if alias != "" && !isOldNew && t.Rel.Name != alias {
continue
}
for _, c := range t.Columns {
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.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- name: UpdateReturningOldStar :one
UPDATE foo SET bar = $1 WHERE id = $2 RETURNING OLD.*;

-- name: UpdateReturningNewStar :one
UPDATE foo SET bar = $1 WHERE id = $2 RETURNING NEW.*;

-- name: UpdateReturningOldNewCols :one
UPDATE foo SET bar = $1 WHERE id = $2 RETURNING OLD.bar, NEW.bar;

-- name: DeleteReturningOldStar :one
DELETE FROM foo WHERE id = $1 RETURNING OLD.*;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE foo (
id serial primary key,
bar text not null,
baz int not null default 0
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "1",
"packages": [
{
"path": "go",
"engine": "postgresql",
"name": "querytest",
"schema": "schema.sql",
"queries": "query.sql"
}
]
}
Loading