Closed
Description
Version
1.15.0
What happened?
This sql query does not work.
I am getting the following error:
table alias "amounts" does not exist
Relevant log output
table alias "amounts" does not exist
Database schema
CREATE TABLE IF NOT EXISTS wallets
(
id uuid NOT NULL DEFAULT uuid_generate_v4() PRIMARY KEY,
address VARCHAR(44) NOT NULL,
type VARCHAR(44) NOT NULL,
balance DECIMAL(32, 18) NULL
);
SQL queries
-- name: FindWallets :many
select id, address, balance, total_balance from
(
select id, address, balance,
sum(balance) over (order by balance desc rows between unbounded preceding and current row) as total_balance,
sum(balance) over (order by balance desc rows between unbounded preceding and current row) - balance as last_balance
from wallets
where type=$1
) amounts
where amounts.last_balance < $2;
Configuration
version: 2
sql:
- schema: "sql/migrations"
queries: "sql/queries"
engine: "postgresql"
gen:
go:
sql_package: "pgx/v4"
out: "internal/store"
emit_prepared_queries: false
emit_json_tags: true
emit_exported_queries: false
emit_db_tags: true
emit_interface: true
emit_exact_table_names: false
emit_empty_slices: true
emit_result_struct_pointers: true
emit_params_struct_pointers: false
emit_enum_valid_method: true
emit_all_enum_values: true
overrides:
- go_type: "github.com/shopspring/decimal.Decimal"
db_type: "pg_catalog.numeric"
- go_type: "github.com/shopspring/decimal.NullDecimal"
db_type: "pg_catalog.numeric"
nullable: true
Playground URL
https://play.sqlc.dev/p/3011dd28fdcc2ee1e3c0c02e19f0fae102e794177017135f63500e43ee0910fe
What operating system are you using?
macOS
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go