Skip to content

Column 'key' not found when using postgres json_each PostgreSQL 14.1 #1480

Open

Description

@vmantese

Version

1.12.0

What happened?

When running sqlc v1.12.0

➜ sqlc compile
# package db
sql/query/advanced.sql:3:84: column "key" does not exist

It appears sqlc compile is not aware of the emitted columns by the json_each function (key and value)

Relevant log output

No response

Database schema

No schema required in this mini example.

SQL queries

--GetInput :one
WITH input as(
    select kv.key category,json_array_elements_text(kv.value) keyword from (select key,value from  json_each(?)) kv
)
select * from input;

Configuration

version: "1"
packages:
  - name: "db"
    sql_package: "pgx/v4"
    path: "internal/db"
    queries: "./sql/query/"
    schema: "./sql/init/"
    engine: "postgresql"
    emit_prepared_queries: true
    emit_interface: false
    emit_exact_table_names: false
    emit_empty_slices: false
    emit_exported_queries: false
    emit_json_tags: true
    emit_result_struct_pointers: false
    emit_params_struct_pointers: false
    emit_methods_with_db_argument: false
    json_tags_case_style: "camel"
    output_db_file_name: "db.go"
    output_models_file_name: "models.go"
    output_querier_file_name: "querier.go"

Playground URL

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

What operating system are you using?

macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

Activity

  1. added
    bugSomething isn't working
    triageNew issues that hasn't been reviewed
    on Mar 9, 2022
  2. changed the title [-]Column 'key' not found when using postgres json_each PostgreSQL 14.1 (Debian 14.1-1.pgdg110+1) [/-] [+]Column 'key' not found when using postgres json_each PostgreSQL 14.1[/+] on Mar 9, 2022
  3. removed
    triageNew issues that hasn't been reviewed
    on Aug 29, 2022
  4. kyleconroy commented on Oct 16, 2023

    @kyleconroy
    Collaborator

    Should be fixed once sqlc supports composite and record types #2760

  5. tardisx commented on Nov 29, 2023

    @tardisx

    Can I confirm that I have the same problem (which will be resolved with #2760) here, with this example:

    https://play.sqlc.dev/p/89b4d32c161e16bcd34d78b9b2f9998eced1e1961ce561be891643074647df78 ?

    Is there any workaround? I don't care about these views (in that I don't need sqlc to generated any code for queries based on these views or their descendants). But they are part of my migration history (tern) and I'd prefer not to temporarily change historical migrations if there is a simpler way.

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

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