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

postgres functions have empty Row structs #2364

Closed
jwc-clinnection opened this issue Jun 24, 2023 · 1 comment
Closed

postgres functions have empty Row structs #2364

jwc-clinnection opened this issue Jun 24, 2023 · 1 comment

Comments

@jwc-clinnection
Copy link
Contributor

Version

1.18.0

What happened?

Functions created for Postgres are not generating fields for returned row structs. For example:

type TestFuncSelectBlogRow struct {
}

I suspect that I'm doing something wrong, but I can't seem to figure this out. Any help would be greatly appreciated. Thank you in advance.

Relevant log output

const testFuncGetTime = `-- name: TestFuncGetTime :one
select  from test_fuct_get_time($1)
`

type TestFuncGetTimeParams struct {
	TestFuctGetTime interface{} `json:"testFuctGetTime"`
}

type TestFuncGetTimeRow struct {
}

func (q *Queries) TestFuncGetTime(ctx context.Context, arg TestFuncGetTimeParams) (TestFuncGetTimeRow, error) {
	row := q.db.QueryRow(ctx, testFuncGetTime, arg.TestFuctGetTime)
	var i TestFuncGetTimeRow
	err := row.Scan()
	return i, err
}

const testFuncSelectBlog = `-- name: TestFuncSelectBlog :one
select  from test_func_select_blog($1)
`

type TestFuncSelectBlogParams struct {
	TestFuncSelectBlog interface{} `json:"testFuncSelectBlog"`
}

type TestFuncSelectBlogRow struct {
}

func (q *Queries) TestFuncSelectBlog(ctx context.Context, arg TestFuncSelectBlogParams) (TestFuncSelectBlogRow, error) {
	row := q.db.QueryRow(ctx, testFuncSelectBlog, arg.TestFuncSelectBlog)
	var i TestFuncSelectBlogRow
	err := row.Scan()
	return i, err
}

const testFuncSelectString = `-- name: TestFuncSelectString :one
select  from test_func_select_string($1)
`

type TestFuncSelectStringParams struct {
	TestFuncSelectString interface{} `json:"testFuncSelectString"`
}

type TestFuncSelectStringRow struct {
}

func (q *Queries) TestFuncSelectString(ctx context.Context, arg TestFuncSelectStringParams) (TestFuncSelectStringRow, error) {
	row := q.db.QueryRow(ctx, testFuncSelectString, arg.TestFuncSelectString)
	var i TestFuncSelectStringRow
	err := row.Scan()
	return i, err
}

Database schema

create function test_func_get_time ()
    returns timestamp AS $$
Begin
    return now();
End;
$$ language plpgsql;

create function test_select_string (in p_string text)
    returns text AS $$
Begin
    return p_string;
End;
$$ language plpgsql;

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

SQL queries

-- name: TestFuncGetTime :one
select * from test_fuct_get_time($1);

-- name: TestFuncSelectString :one
select * from test_func_select_string($1);

-- name: TestFuncSelectBlog :one
select * from test_func_select_blog($1);

Configuration

No response

Playground URL

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

What operating system are you using?

Linux

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

@jwc-clinnection jwc-clinnection added bug Something isn't working triage New issues that hasn't been reviewed labels Jun 24, 2023
@kyleconroy kyleconroy added 📚 postgresql 🔧 golang 💻 linux and removed triage New issues that hasn't been reviewed labels Jul 6, 2023
kyleconroy added a commit that referenced this issue Oct 18, 2023
kyleconroy added a commit that referenced this issue Oct 18, 2023
* test: Add case for #2132
* test: Add case for #2152
* test: Mark case for #2152
* test: Add case for #2187
* test: Add case for #2226
* test: Add case for #2364
* test: Add case for #2386
* test: Add case for #2538
* test: Add case for #2644
* test: Add case for #2731
@kyleconroy
Copy link
Collaborator

This is fixed in v1.23.0 by enabling the database-backed query analyzer. We added a test case for this issue so it won’t break in the future.

You can play around with the working example on the playground

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

No branches or pull requests

2 participants