Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

relation does not exist with insert using CTE #3847

Open
wouthoekstra opened this issue Feb 17, 2025 · 0 comments
Open

relation does not exist with insert using CTE #3847

wouthoekstra opened this issue Feb 17, 2025 · 0 comments
Labels

Comments

@wouthoekstra
Copy link

Version

1.28.0

What happened?

When creating an insert query using a CTE results in an error. The relation with the CTE does not exist, according to sqlc:

relation "potential_authors" does not exist

I've recreated a simplified version of the issue in the playground.

Relevant log output

Database schema

CREATE TABLE authors (
  id   BIGSERIAL PRIMARY KEY,
  name text      NOT NULL,
  bio  text
);

CREATE TABLE dummy (
  id   BIGSERIAL PRIMARY KEY,
  name text      NOT NULL,
  bio  text
);

SQL queries

-- name: CreateAuthor :exec
INSERT INTO authors
WITH potential_authors AS (
  SELECT id, name, bio
    FROM dummy
)

SELECT id, name, bio
  FROM potential_authors;

Configuration

version: "2"
cloud:
    organization: ""
    project: ""
    hostname: ""
sql:
  - schema: ./sql/schema.sql
    queries: ./sql/queries
    engine: mysql
    gen:
      go:
        package: sqlc
        out: ./_sqlc
        emit_json_tags: true
        emit_prepared_queries: false
        emit_interface: false
        emit_exact_table_names: true
overrides:
    go: null
plugins: []
rules: []
options: {}

Playground URL

https://play.sqlc.dev/p/39948b645032d9910dee27400711e18e91a35b803282bc256bee82afa681bff8

What operating system are you using?

Linux

What database engines are you using?

MySQL

What type of code are you generating?

Go

@wouthoekstra wouthoekstra added the bug Something isn't working label Feb 17, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant