-
Notifications
You must be signed in to change notification settings - Fork 902
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Version
1.25.0
What happened?
Sqlc encounters issues when attempting to recognize table aliases specified within the WHERE clause, particularly when filtering selections using the syntax alias_table.field = 'something'.
I've provided a simple example to replicate the issue
Relevant log output
sqlc generate failed.
# package
query.sql:8:39: table alias "all_users" does not exist
Database schema
-- Create users table
CREATE TABLE users (
id SERIAL PRIMARY KEY,
email VARCHAR(100) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Create posts table
CREATE TABLE admins (
id SERIAL PRIMARY KEY,
email VARCHAR(100) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
SQL queries
-- name: GetAllUsers :many
WITH all_users AS (
SELECT id, email FROM users
UNION
SELECT id, email FROM admins
)
SELECT id, email FROM all_users where all_users.email=$1;
Configuration
version: "2"
sql:
- schema: "./db/migrations/"
queries: "./pkg/postgres/queries/"
engine: "postgresql"
gen:
go:
package: "postgres"
out: "./pkg/postgres/sqlc"
emit_json_tags: true
emit_prepared_queries: false
emit_interface: true
emit_exact_table_names: false
emit_empty_slices: true
Playground URL
https://play.sqlc.dev/p/388ae1f5e3a9ab6c0185bdfce9ead7acbbb6ece3d6a52d828cd40184b109caf3
What operating system are you using?
Linux
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go
sarvsav, stefanvanburen, brojonat, timjchin, veqryn and 2 more
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working