Skip to content

Unable to generate parameter type where named parameters are on each side of an equal sign #1187

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

Closed
boecklim opened this issue Sep 14, 2021 · 3 comments
Labels

Comments

@boecklim
Copy link

boecklim commented Sep 14, 2021

Version

1.10.0

What happened?

The parameter data type is not generated by sqlc if in a situation query for a column with datatype jsonb where named parameters are on each side of an equal sign.

This type should be generated but it isn't

type GetFooByBarNumberedParams struct {
	key   pqtype.NullRawMessage
	value pqtype.NullRawMessage
}

Also the query generated is not what is expected

const getFooByBarNamed = `-- name: GetFooByBarNamed :one
SELECT bar_named FROM foo_named
WHERE bar_named->>@key = $1
LIMIT 1
`

It would be expected that this query is generated

const getFooByBarNamed = `-- name: GetFooByBarNamed :one
SELECT bar_named FROM foo_named
WHERE bar_named->>@key = @value
LIMIT 1
`

Relevant log output

No response

Database schema

CREATE TABLE foo_named (
    bar_named jsonb
);

SQL queries

-- name: GetFooByBarNamed :one
SELECT bar_named FROM foo_named
WHERE bar_named->>@key = @value
LIMIT 1;
​

Configuration

---

version: "1"
packages:
  - name: "db"
    path: "internal/db"
    queries: "./queries/"
    schema: "./migrations/"
    engine: "postgresql"
    emit_prepared_queries: false
    emit_interface: false
    emit_exact_table_names: false
    emit_empty_slices: false
    emit_json_tags: false

Playground URL

https://play.sqlc.dev/p/357e581cff2aec6d6d835ec993dc17eb8480686b7377d2704508a58da1a71313

What operating system are you using?

Linux

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

@boecklim boecklim added bug Something isn't working triage New issues that hasn't been reviewed labels Sep 14, 2021
@kyleconroy kyleconroy added 🔧 golang 📚 postgresql and removed triage New issues that hasn't been reviewed labels Sep 20, 2021
@kyleconroy
Copy link
Collaborator

The named parameter shorthand sometimes doesn't work (see #605). It looks like things are working correctly if you use dollar sign parameters. It also seems to work if you use sqlc.arg instead of the @ parameters: https://play.sqlc.dev/p/c893b612321ff5fae8559cbf0d817944438d32043c3d2d5a2d7c064f2e910a07

Does this fix it for you?

@breml
Copy link

breml commented Sep 21, 2021

@kyleconroy We forgot about sqlc.arg, this solves the problem for us. The dollar sign variant did not really produce good field names on the struct, so this was not really an option for us.

Is this a now limitation of using @, which comes from the postgres SQL parser or is it still a bug, that @ can not be used?

@kyleconroy
Copy link
Collaborator

The limitation is the PostgreSQL parser itself.

@kyleconroy kyleconroy closed this as not planned Won't fix, can't repro, duplicate, stale Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants