You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the playground example I supplied, you can see that I have used both sqlc.arg and sqlc.narg when casting to TEXT[], but the generated code does not contain sql.NullString for the second argument as I expected.
Input:
-- name: batchUpsert :execINSERT INTO authors (id, name, bio)
VALUES (
unnest(sqlc.arg(ids)::BIGINT[]),
unnest(sqlc.arg(names)::TEXT[]),
unnest(sqlc.narg(bios)::TEXT[])
) ON CONFLICT (id) DO UPDATESET
name =EXCLUDED.name,
bio =EXCLUDED.bio;
If I take away the array part of the cast, so ::TEXT instead of ::TEXT[], it seems to work as expected, so I assume that this is a bug, and not intentional.
If there are any other way to have a dynamic batching system someone could recommend, I will give that a try, but so far, this is what I have.
I solved my problem by overriding the generated types to use the pgtype package because these types are nullable. Then I create dependency inversion functions which take in the application types and converts them to the pgtype types.
CREATETABLEexample (
name textNOT NULL
);
-- name: FailingWithNullableArrayTextParam :manySELECT*FROM example
WHEREexample.name= ANY (sqlc.narg('expected_nullable_array')::text[]);
-- name: WorkingWithNullableSingleTextParam :manySELECT*FROM example
WHEREexample.name=sqlc.narg('is_nullable')::text;
If I cast a sqlc.narg to an array type I expect it to result in a nullable param. But the actual param is not nullable:
Activity
angaz commentedon Sep 28, 2022
I solved my problem by overriding the generated types to use the
pgtypepackage because these types are nullable. Then I create dependency inversion functions which take in the application types and converts them to thepgtypetypes.So my
sqlc.yamllooks something like this:dhermes commentedon Dec 1, 2022
Here is a slightly more focused hack. Introduce an alias type in the DB, e.g.
Configure via
and then use
akhmadnurmuhammad commentedon Dec 6, 2022
still looking forward for this issue, i have same problem here but still not working, FYI i'm using version 1 for configuration
SOLVED
try adding this at sqlc.yaml for overrides
overrides:
- db_type: "pg_catalog.timestamp"
go_type: "database/sql.NullTime"
and the queries like this
unnest(sqlc.narg('created_at')::TIMESTAMP[])
ekron commentedon Aug 12, 2023
Just to add another example.
With this sql:
If I cast a sqlc.narg to an array type I expect it to result in a nullable param. But the actual param is not nullable:
It works for a param cast to a non-array.
You can see the result here:
https://play.sqlc.dev/p/33b38fa273e0c059979f62e1dfc95c7a1edd76f8ef209e21f04fa97abf71ecac
I have tried with enums and other types, but the bug remains the same.
GerardRodes commentedon Sep 8, 2023
I wouldn't add the
pgx/v4label, it happens in every scenario:https://play.sqlc.dev/p/8768da94721f7c53e21b0179cf1644be3e96d0ef5209da9edafe87342f162c1a
unnest(sqlc.narg(bios)::TEXT[])becomesBios []stringand should be some kind of nulable stringkokhans commentedon Jul 28, 2025
Hello everyone, any updates on this issue?
fix: let sqlc output nullable array
fix: let sqlc output nullable array
fix: let sqlc output nullable array
fix: let sqlc output nullable array
fix: let sqlc output nullable array
fix: let sqlc output nullable array
fix: let sqlc output nullable array
fix: let sqlc output nullable array
fix: let sqlc output nullable array
fix: let sqlc output nullable array
fix: let sqlc output nullable array
fix: let sqlc output nullable array
database/gendb: adapt to changes, improvements