Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Query with SELECT "table".* produces invalid SELECT table.columnx.* #2195

Closed
coolaj86 opened this issue Apr 6, 2023 · 0 comments · Fixed by #2576
Closed

Query with SELECT "table".* produces invalid SELECT table.columnx.* #2195

coolaj86 opened this issue Apr 6, 2023 · 0 comments · Fixed by #2576

Comments

@coolaj86
Copy link

coolaj86 commented Apr 6, 2023

Version

1.17.2

What happened?

The trailing .* gets appended to the last column when trying to scope * to a specific table in a join query.

SELECT "ledger".* ...

becomes

SELECT ledger.id, ledger.submitted_at.* ...

Here are the exact inputs and outputs

-- name: IndividualListRecords :many
SELECT
    "ledger".*
FROM
    "ledger"
INNER JOIN
    "ledger_party"
        ON "ledger"."id" = "ledger_party"."ledger_id"
INNER JOIN
    "party_identifier"
        ON "ledger_party"."party_id" = "party_identifier"."party_id"
WHERE
    "party_identifier"."party_id" = $1
        OR
    (
        "party_identifier"."identifier" = $2
        AND $2 != ''
    )
;
const individualListRecords = `-- name: IndividualListRecords :many
SELECT
    ledger.id, ledger._old_id, ledger.record_type, ledger.account_id, ledger.data, ledger.submitted_by, ledger.submitted_as, ledger.submitted_at.*
FROM
    "ledger"
INNER JOIN
    "ledger_party"
        ON "ledger"."id" = "ledger_party"."ledger_id"
INNER JOIN
    "party_identifier"
        ON "ledger_party"."party_id" = "party_identifier"."party_id"
WHERE
    "party_identifier"."party_id" = $1
        OR
    (
        "party_identifier"."identifier" = $2
        AND $2 != ''
    )
`

I need to go fix this. I'm just documenting it here for now. I see there are hundreds of open issues, so HMU if you need more info to investigate and I'll provide it.

Relevant log output

ERROR: missing FROM-clause entry for table "submitted_at" (SQLSTATE 42P01)

Database schema

No response

SQL queries

-- name: IndividualListRecords :many
SELECT
    "ledger".*
FROM
    "ledger"
INNER JOIN
    "ledger_party"
        ON "ledger"."id" = "ledger_party"."ledger_id"
INNER JOIN
    "party_identifier"
        ON "ledger_party"."party_id" = "party_identifier"."party_id"
WHERE
    "party_identifier"."party_id" = $1
        OR
    (
        "party_identifier"."identifier" = $2
        AND $2 != ''
    )
;

Configuration

version: 2
sql:
  - engine: "postgresql"
    schema: "./migrations/"
    queries: "./sql/queries/"
    gen:
      go:
        package: "reportsv2"
        out: "reportsv2"
        sql_package: "pgx/v4"
        emit_json_tags: true
        json_tags_case_style: "snake"
        overrides:
          - column: "party_identifier.id"
            go_struct_tag: 'json:"-"'
          - column: "party_identifier.party_id"
            go_struct_tag: 'json:"-"'

Playground URL

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

What operating system are you using?

macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

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

Successfully merging a pull request may close this issue.

2 participants