sqlc-dev / sqlc

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

pgx go generate execresult and execlastid not working #3699

Open optimuspaul opened 1 week ago

optimuspaul commented 1 week ago

Version

1.27.0

What happened?

created some tables and queries to insert values into the tables. the generated code doesn't generate sensible or expected results.

Relevant log output

No response

Database schema

CREATE TABLE users (
    id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
    email text NOT NULL UNIQUE,
    password text,
    enabled boolean NOT NULL DEFAULT TRUE
);

CREATE TABLE lusers (
    id serial PRIMARY KEY,
    email text NOT NULL UNIQUE,
    password text,
    enabled boolean NOT NULL DEFAULT TRUE
);

SQL queries

-- name: CreateUserA :execresult
insert into users (email, password, enabled) values ($1, $2, $3) returning *;

-- name: CreateUserB :execlastid
insert into users (email, password, enabled) values ($1, $2, $3) returning *;

-- name: CreateUserC :execrows
insert into users (email, password, enabled) values ($1, $2, $3) returning *;

-- name: CreateUserD :exec
insert into users (email, password, enabled) values ($1, $2, $3) returning *;

Configuration

{
  "version": "2",
  "sql": [{
    "schema": "schema.sql",
    "queries": "query.sql",
    "engine": "postgresql",
    "gen": {
      "go": {
        "out": "db",
        "sql_package": "pgx/v5" 
      }
    }
  }]
}

Playground URL

https://play.sqlc.dev/p/1f7b12addc3f2d40a3e92ab77d5ea4e6e988e3c1cb1a521801a4023e2dc5b4dc

What operating system are you using?

macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

weeco commented 2 days ago

You have to use :one or :many rather than :execresult