Add a NULL value to a varchar array
Version
1.13.0
What happened?
I have a query
-- name: Test :exec
INSERT INTO test (id, body)
VALUES (
UNNEST($1::uuid[]), UNNEST($2::varchar[]));
there is a generated struct
type TestParams struct {
Column1 []uuid.UUID `json:"column_1"`
Column2 []string `json:"column_2"`
}
sometimes i need to pass to body a null value. I can't pass NULL to string. As a quick fix, I changed the generated file. Yes, I know it's a crime against humanity, but it solves my problem:))
I changed []string -> []interface{} in the TestParams struct.
Relevant log output
No response
Database schema
create table test
(
id uuid not null,
body varchar,
)
SQL queries
No response
Configuration
No response
Playground URL
No response
What operating system are you using?
macOS
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go
Using sqlc.narg() doesn't work: https://play.sqlc.dev/p/1086edbe69a9fcee4861557b9edfcb9c1294294596d41d5095d9734bd311d772
Is there any solution so far?
any other workaround for this?
any other workaround for this?
@bagashiz, @Abdullah-AlAttar, a bit hacky but works (if you don't require empty strings )
sql INSERT INTO test (id, body) SELECT UNNEST($1::uuid[]), NULLIF(UNNEST($2::varchar[]), '');