Merge branch 'arjen-ag5/master' into pg_arrays

# Conflicts:
#	generator/template/model_template.go
#	generator/template/sql_builder_template.go
#	internal/jet/expression.go
#	postgres/cast.go
#	postgres/columns.go
#	postgres/expressions.go
#	postgres/insert_statement_test.go
#	postgres/literal.go
#	tests/postgres/alltypes_test.go
#	tests/postgres/generator_template_test.go
#	tests/postgres/scan_test.go
#	tests/postgres/select_test.go
This commit is contained in:
go-jet 2025-10-16 13:44:18 +02:00
commit 45d4ced9b0
25 changed files with 575 additions and 85 deletions

View file

@ -175,27 +175,30 @@ RETURNING table1.col1 AS "table1.col1",
}
func TestInsert_ON_CONFLICT_ON_CONSTRAINT(t *testing.T) {
stmt := table1.INSERT(table1Col1, table1ColBool).
VALUES("one", "two").
VALUES("1", "2").
ON_CONFLICT().ON_CONSTRAINT("idk_primary_key").
DO_UPDATE(
SET(table1ColBool.SET(Bool(false)),
table2ColInt.SET(Int(1)),
ColumnList{table1Col1, table1ColBool}.SET(ROW(Int(2), String("two"))),
).WHERE(table1Col1.GT(Int(2)))).
RETURNING(table1Col1, table1ColBool)
stmt := table1.INSERT(table1Col1, table1ColBool, table1ColStringArray).
VALUES("one", "two", "three").
VALUES("1", "2", "3").
ON_CONFLICT().ON_CONSTRAINT("idk_primary_key").DO_UPDATE(
SET(table1ColBool.SET(Bool(false)),
table2ColInt.SET(Int(1)),
table1ColStringArray.SET(StringArray([]string{"one"})),
ColumnList{table1Col1, table1ColBool, table1ColStringArray}.SET(jet.ROW(Int(2), String("two"), StringArray([]string{"two"}))),
).WHERE(table1Col1.GT(Int(2))),
).
RETURNING(table1Col1, table1ColBool, table1ColStringArray)
assertDebugStatementSql(t, stmt, `
INSERT INTO db.table1 (col1, col_bool)
VALUES ('one', 'two'),
('1', '2')
INSERT INTO db.table1 (col1, col_bool, col_string_array)
VALUES ('one', 'two', 'three'),
('1', '2', '3')
ON CONFLICT ON CONSTRAINT idk_primary_key DO UPDATE
SET col_bool = FALSE::boolean,
col_int = 1,
(col1, col_bool) = ROW(2, 'two'::text)
col_string_array = '{"one"}',
(col1, col_bool, col_string_array) = ROW(2, 'two'::text, '{"two"}')
WHERE table1.col1 > 2
RETURNING table1.col1 AS "table1.col1",
table1.col_bool AS "table1.col_bool";
table1.col_bool AS "table1.col_bool",
table1.col_string_array AS "table1.col_string_array";
`)
}