Skip to content

Star expansion incorrect for functions that return records #2916

New issue

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

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

Already on GitHub? # to your account

Open
kyleconroy opened this issue Oct 25, 2023 · 0 comments
Open

Star expansion incorrect for functions that return records #2916

kyleconroy opened this issue Oct 25, 2023 · 0 comments

Comments

@kyleconroy
Copy link
Collaborator

Version

1.23.0

What happened?

For functions that return records, sqlc will expand to a single column with the same name as the function. This works for PostgreSQL, but results in an interface type due to #2760. Instead, by default, star expansion should create a column for each field on the record.

// CURRENT
const testFuncSelectBlog = `-- name: TestFuncSelectBlog :many
select test_select_blog from test_select_blog($1)
`

// WANTED
const testFuncSelectBlog = `-- name: TestFuncSelectBlog :many
select id, name from test_select_blog($1)
`

Relevant log output

No response

Database schema

create table blog (
    id serial primary key,
    name text not null
);

create function test_select_blog(in p_id int)
    returns table (id int, name text) AS $$
BEGIN RETURN QUERY
    select id, name from blog where id = p_id;
END;
$$ language plpgsql;

SQL queries

-- name: TestFuncSelectBlog :many
select * from test_select_blog($1);

Configuration

version: "2"
cloud:
  project: "<PROJECT_ID>"
sql:
- schema: "schema.sql"
  queries: "query.sql"
  engine: "postgresql"
  database:
    managed: true
  gen:
    go:
      out: db
      sql_package: "pgx/v5"

Playground URL

https://play.sqlc.dev/p/0e0719e69ade689d47546ee075d7f0ae2c9c0fb67f4fd31484841bd70d070197

What operating system are you using?

macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

No response

@kyleconroy kyleconroy added bug Something isn't working triage New issues that hasn't been reviewed 📚 postgresql 🔧 golang 💻 darwin analyzer and removed triage New issues that hasn't been reviewed labels Oct 25, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

1 participant