Skip to content

keyword with causing "column does not exist" #1515

Closed
@kubik51

Description

@kubik51

Version

1.12.0

What happened?

I wanted to make an update query that also returns some more detailed data from other tables. The update query itself works fine, but the "WITH" statement causes the "column does not exist" error during code generation in already tested update query.

Relevant log output

No response

Database schema

create table attribute_value
(
    id              bigserial not null,
    val             text      not null,
    attribute       bigint    not null
);

create table attribute
(
    id              bigserial      not null,
    name            text           not null
);

SQL queries

-- name: UpdateAttributeValueDoesntWork :one
with updated_attribute as (UPDATE attribute_value
    SET
        val = CASE WHEN @filter_value::bool THEN @value ELSE val END
    WHERE attribute_value.id = @id
    RETURNING id,attribute,val)
select updated_attribute.id, val, name
from updated_attribute
         left join attribute on updated_attribute.attribute = attribute.id;
		 
-- name: UpdateAttributeValueWorks :one
UPDATE attribute_value
    SET
        val = CASE WHEN @filter_value::bool THEN @value ELSE val END
    WHERE attribute_value.id = @id
    RETURNING id,attribute,val;

Configuration

No response

Playground URL

https://play.sqlc.dev/p/ba79ccad12759729ce4f260f70f3250de323a0050d2172e53d06f5ec1f83ee0d

What operating system are you using?

Linux

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions