sqlc
sqlc copied to clipboard
sqlc cannot "find" virtual columns in postgresql CTE
Version
1.27.0
What happened?
queries.sql:22:12: column "list_name" does not exist
Relevant log output
No response
Database schema
create table lists (
id serial not null primary key,
name text not null
);
create table archive (
message_id text not null primary key,
in_reply_to_id text,
list_id int references lists(id),
subject text not null,
timestamp timestamp not null default now()
);
create table archive_timestamps (
id serial primary key,
list_id int references lists(id) on delete cascade,
year_month timestamp unique not null default now()
);
SQL queries
-- name: AddToArchive :exec
with
pms as (
select $3 as list_name, $5 as timestamp
),
list as (
select id from lists where name = pms.list_name
),
none as (
insert into archive (message_id, in_reply_to_id, list_id, subject, timestamp)
values ($1, $2, list.id, $4, pms.timestamp)
)
insert into archive_timestamps (list_id, year_month)
values (
list.id,
date_part('year', pms.timestamp) || '-' || date_part('month', pms.timestamp) || '-01'
) on conflict do nothing;
Configuration
version: 2
sql:
- engine: "postgresql"
schema: "migrate/*.sql"
queries: "queries.sql"
gen:
go:
package: "queries"
out: "queries"
Playground URL
No response
What operating system are you using?
Linux
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go