Skip to content

Add sqlc+postgres DELETE/USING issue demonstration #6

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

Closed

Conversation

buildbreaker
Copy link
Owner

@buildbreaker buildbreaker commented Jun 28, 2022

For issue: sqlc-dev/sqlc#1714

Version

1.14.0

What happened?

I'm trying to write a DELETE query which I want to join the results with another table. The way that I am familiar with is to use the USING keyword but that seems to be scoped to the WHERE clause only. When I try returning the columns from the USING table, sqlc generate complains that it cant find the column in the RETURNING block.

I have an example with CI testing/output here.
Add sqlc DELETE/USING issue demonstration contains the commit for the "working path".
failure case introduces the problematic query. The CI error can be found here.

I can get around this specific issue by using CTEs but it'd be nice to get this way working also!

Relevant log output

Error message from the "Failing query" in the SQL queries section:

    # package demo
    query.sql:26:15: column "b_id" does not exist

Database schema

CREATE TABLE a
(
    a_id TEXT,
    b_id_fk TEXT
);
CREATE TABLE b
(
    b_id TEXT
);

SQL queries

Query that works:

-- name: GetSomeDeletedOk :many
DELETE FROM a
    USING b
WHERE a.b_id_fk = b.b_id
    RETURNING *; -- note no columns from b in model

Failing query:

-- name: GetSomeDeletedNotOk :many
DELETE FROM a
USING b
WHERE a.b_id_fk = b.b_id
RETURNING b.b_id; -- column "b_id" does not exist

Configuration

version: 1
packages:
  - path: "demo"
    name: "demo"
    engine: "postgresql"
    schema: "schema.sql"
    queries: "query.sql"

Playground URL

https://play.sqlc.dev/p/1ca4c468637ee1d35988be307ea517680fce1fb63af2b816a5a9af4361bf4f68

What operating system are you using?

macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

@buildbreaker buildbreaker changed the title Add sqlc DELETE/USING issue demonstration Add sqlc+postgres DELETE/USING issue demonstration Jun 28, 2022
@buildbreaker buildbreaker force-pushed the achiu/add-sqlc-delete-using-issue-demonstration branch 3 times, most recently from 7872e90 to 0059867 Compare June 28, 2022 21:25
@buildbreaker buildbreaker force-pushed the achiu/add-sqlc-delete-using-issue-demonstration branch from 0059867 to 6874f04 Compare June 28, 2022 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant