-
-
Notifications
You must be signed in to change notification settings - Fork 259
Open
Labels
Description
Provided this model:
type Data struct {
ID int64 `bun:",pk"`
Tags []string `bun:",array"`
}And using this ValuesQuery to create a CTE does not create a valid SQL for PostgreSQL:
_, err := db.NewCreateTable().Model((*Data)(nil)).Exec(ctx)
data := make([]Data, 10)
for i := range 10 {
data[i] = Data{
ID: int64(i),
Tags: []string{"foo", "bar"},
}
}
q := tr.db.NewValues(&data)
t.Log(tr.db.NewSelect().With("foo", &data).String())This prints:
WITH "foo" ("id", "tags") AS (VALUES (0::BIGINT, '{"foo","bar"}'::VARCHAR[]), (1::BIGINT, '{"foo","bar"}'::VARCHAR[]), (2::BIGINT, '{"foo","bar"}'::VARCHAR[]), (3::BIGINT, '{"foo","bar"}'::VARCHAR[]), (4::BIGINT, '{"foo","bar"}'::VARCHAR[]), (5::BIGINT, '{"foo","bar"}'::VARCHAR[]), (6::BIGINT, '{"foo","bar"}'::VARCHAR[]), (7::BIGINT, '{"foo","bar"}'::VARCHAR[]), (8::BIGINT, '{"foo","bar"}'::VARCHAR[]), (9::BIGINT, '{"foo","bar"}'::VARCHAR[])) SELECT *which is invalid with:
ERROR: column \"tags\" is of type character varying[] but expression is of type character varying (SQLSTATE 42804
It seems to work for other cases like insert.
Could you help me to make it work?