Skip to content

Error when generating semantically correct postgres SQL #1858

Closed
@patrickdevivo

Description

@patrickdevivo

Version

1.15.0

What happened?

Hi! First of all thank you for all the hard work going into sqlc - we're big fans! We use sqlc for this project and encountered an error when trying to compile a query that has 3 "parts" in a column name in a select:

unknown number of fields: 3

I've made this small repo to show reproduction of the issue: https://github.com/mergestat/sqlc-compile-bug

The error seems to originate here: https://github.com/kyleconroy/sqlc/blob/0a1b04eb47c80236db176805fe43f709042b805c/internal/compiler/output_columns.go#L474 where it looks like only 1 or 2 "parts" are permitted, when it should be possible to allow 3 (in our queries at least, which run fine in postgres directly).

We've been able to get around this by aliasing the schema.table in our query, so we only need to refer to a column with 2 "parts" - but it would still be nice to avoid this limitation (as it would allow us to keep our queries a bit cleaner, especially in more complex ones).

Relevant log output

unknown number of fields: 3

Database schema

CREATE SCHEMA some_schema;

CREATE TABLE some_schema.some_table (
  id   BIGSERIAL PRIMARY KEY,
  some_column  text
);

SQL queries

-- AllRowsOK :many
SELECT id, some_table.some_column FROM some_schema.some_table;

-- AllRowsBug :many
SELECT id, some_schema.some_table.some_column FROM some_schema.some_table;

Configuration

version: "2"
sql:
  - engine: "postgresql"
    queries: "query.sql"
    schema: "schema.sql"
    gen:
      go:
        package: "example"
        out: "example"

Playground URL

No response

What operating system are you using?

Linux, macOS

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