Skip to content

sqlite: CREATE TABLE ... AS SELECT creates a table with no columns #4683

Open

Description

@manuelschoene

Version

1.31.1

What happened?

In the SQLite engine, a table created with CREATE TABLE … AS SELECT ends up in the catalog with no columns. Any query that reads a column from it fails with column "…" does not exist. Both analysis paths are affected: the default analyzer and the core analyzer (SQLCEXPERIMENT=coreanalyzer).

PostgreSQL and DuckDB already support the same schema.

Expected: the table gets the columns of its SELECT (here id INTEGER, name TEXT), and the query generates a T2 model.

Relevant log output

# default analyzer
query.sql:2:8: column "id" does not exist

# SQLCEXPERIMENT=coreanalyzer
query.sql:1:1: unknown column "id"

Database schema

CREATE TABLE t (id INTEGER PRIMARY KEY, name TEXT NOT NULL, score INTEGER NOT NULL, created TEXT);
CREATE TABLE t2 AS SELECT id, name FROM t;

SQL queries

-- name: ListCtas :many
SELECT id, name FROM t2;

Configuration

version: "2"
sql:
  - engine: "sqlite"
    schema: "schema.sql"
    queries: "query.sql"
    gen:
      go:
        package: "db"
        out: "db"

Playground URL

No response

What operating system are you using?

Linux

What database engines are you using?

SQLite

What type of code are you generating?

Go

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions