sqlc-dev / sqlc

Generate type-safe code from SQL
https://sqlc.dev
MIT License
13.59k stars 812 forks source link

column "ordinality" does not exist when generating golang code #3540

Open blanc42 opened 3 months ago

blanc42 commented 3 months ago

Version

1.26.0

What happened?

JOIN LATERAL (
      SELECT ordinality AS ord
      FROM jsonb_array_elements_text(p.variants) WITH ORDINALITY
      WHERE value = v.id::text
) idx ON true

get_multiple_products.sql:99:21: column "ordinality" does not exist

the whole query worked used directly with the database

Relevant log output

get_multiple_products.sql:99:21: column "ordinality" does not exist

Database schema

JOIN LATERAL (
      SELECT ordinality AS ord
      FROM jsonb_array_elements_text(p.variants) WITH ORDINALITY
      WHERE value = v.id::text
) idx ON true

SQL queries

SELECT
    v.id AS variant_id,
    v.name AS variant_name,
    (
        SELECT JSON_AGG( 
            JSON_BUILD_OBJECT(
                'id', vo.id,
                'value', vo.value,
                'data', vo.data
            )
        )
        FROM variant_options vo
        WHERE vo.variant_id = v.id
    ) AS options,
    idx.ord
FROM
    variants v
JOIN LATERAL (
    SELECT ordinality AS ord
    FROM jsonb_array_elements_text(p.variants) WITH ORDINALITY
    WHERE value = v.id::text
) idx ON true
WHERE
    v.id = ANY(
    SELECT jsonb_array_elements_text(p.variants)
    )
GROUP BY
    v.id, v.name, idx.ord

Configuration

version: "2"
sql:
  - engine: "postgresql"
    queries: "./pkg/db/query/"
    schema: "./pkg/db/schema/"
    gen:
      go:
        package: "db"
        out: "./pkg/db/sqlc"
        sql_package: "pgx/v5"
        emit_json_tags: true
        emit_prepared_queries: false
        emit_interface: false
        emit_exact_table_names: false
        overrides:
          - db_type: "jsonb"
            nullable: true
            engine: "postgresql"
            go_type:
              import: "encoding/json"
              type: "RawMessage"

Playground URL

No response

What operating system are you using?

Linux

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go