Skip to content

fix(compiler): Pull in array information from analyzer #2864

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 12 commits into from
Oct 18, 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
4 changes: 4 additions & 0 deletions internal/compiler/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func combineAnalysis(prev *analysis, a *analyzer.Analysis) *analysis {
if len(prev.Columns) == len(cols) {
for i := range prev.Columns {
prev.Columns[i].DataType = cols[i].DataType
prev.Columns[i].IsArray = cols[i].IsArray
prev.Columns[i].ArrayDims = cols[i].ArrayDims
}
} else {
embedding := false
Expand All @@ -73,6 +75,8 @@ func combineAnalysis(prev *analysis, a *analyzer.Analysis) *analysis {
if len(prev.Parameters) == len(params) {
for i := range prev.Parameters {
prev.Parameters[i].Column.DataType = params[i].Column.DataType
prev.Parameters[i].Column.IsArray = params[i].Column.IsArray
prev.Parameters[i].Column.ArrayDims = params[i].Column.ArrayDims
}
} else {
prev.Parameters = params
Expand Down
3 changes: 2 additions & 1 deletion internal/endtoend/testdata/cte_recursive_employees/issue.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
https://github.com/sqlc-dev/sqlc/issues/1219
https://github.com/sqlc-dev/sqlc/issues/1219
https://github.com/sqlc-dev/sqlc/issues/1912

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

1 change: 1 addition & 0 deletions internal/endtoend/testdata/cte_update_multiple/issue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/sqlc-dev/sqlc/issues/1916
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"contexts": ["managed-db"]
}

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,28 @@
-- name: UpdateUserAddressWithAddress :one
WITH t1 AS (
UPDATE "address" as a
SET
address_line = COALESCE(sqlc.narg(address_line),address_line),
region = COALESCE(sqlc.narg(region),region),
city= COALESCE(sqlc.narg(city),city)
WHERE id = COALESCE(sqlc.arg(id),id)
RETURNING a.id, a.address_line, a.region, a.city
),

t2 AS (
UPDATE "user_address"
SET
default_address = COALESCE(sqlc.narg(default_address),default_address)
WHERE
user_id = COALESCE(sqlc.arg(user_id),user_id)
AND address_id = COALESCE(sqlc.arg(address_id),address_id)
RETURNING user_id, address_id, default_address
)

SELECT
user_id,
address_id,
default_address,
address_line,
region,
city From t1,t2;
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
CREATE TABLE "user" (
"id" bigserial PRIMARY KEY NOT NULL,
"username" varchar NOT NULL,
"email" varchar UNIQUE NOT NULL,
"password" varchar NOT NULL,
"telephone" int NOT NULL DEFAULT 0,
"default_payment" bigint,
"created_at" timestamptz NOT NULL DEFAULT (now()),
"updated_at" timestamptz NOT NULL DEFAULT '0001-01-01 00:00:00Z'
);

CREATE TABLE "address" (
"id" bigserial PRIMARY KEY NOT NULL,
"address_line" varchar NOT NULL,
"region" varchar NOT NULL,
"city" varchar NOT NULL,
"created_at" timestamptz NOT NULL DEFAULT (now()),
"updated_at" timestamptz NOT NULL DEFAULT '0001-01-01 00:00:00Z'
);

CREATE TABLE "user_address" (
"user_id" bigint NOT NULL,
"address_id" bigint UNIQUE NOT NULL,
"default_address" bigint,
"created_at" timestamptz NOT NULL DEFAULT (now()),
"updated_at" timestamptz NOT NULL DEFAULT '0001-01-01 00:00:00Z'
);
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"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/sqlc-dev/sqlc/issues/1917
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"contexts": ["managed-db"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- name: SelectOne :one
SELECT 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE TABLE test_table (
id STRING
);
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"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# package querytest
query.sql:1:1: rpc error: code = FailedPrecondition desc = type "string" does not exist (42704)
CREATE TABLE test_table (
id STRING
);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/sqlc-dev/sqlc/issues/1545
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"contexts": ["managed-db"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- name: GetTotalEarned :one
SELECT COALESCE(SUM(earned), 0) as total_earned
FROM grouped_kpis
WHERE day = @day;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE kpis (
ts TIMESTAMPTZ,
event_id TEXT NOT NULL
);

CREATE MATERIALIZED VIEW IF NOT EXISTS grouped_kpis AS
SELECT date_trunc('1 day', ts) as day, COUNT(*)
FROM kpis
GROUP BY 1;
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"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# package querytest
query.sql:2:21: column "earned" does not exist
1 change: 1 addition & 0 deletions internal/endtoend/testdata/delete_using/issue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/sqlc-dev/sqlc/issues/1714
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"contexts": ["managed-db"]
}
32 changes: 32 additions & 0 deletions internal/endtoend/testdata/delete_using/postgresql/pgx/go/db.go

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.

Loading