MCPcopy
hub / github.com/jackc/pgx / TestConnQueryRowConstraintErrors

Function TestConnQueryRowConstraintErrors

stdlib/sql_test.go:1175–1212  ·  view source on GitHub ↗

https://github.com/jackc/pgx/issues/958

(t *testing.T)

Source from the content-addressed store, hash-verified

1173
1174// https://github.com/jackc/pgx/issues/958
1175func TestConnQueryRowConstraintErrors(t *testing.T) {
1176 testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) {
1177 skipPostgreSQLVersionLessThan(t, db, 11)
1178 skipCockroachDB(t, db, "Server does not support deferred constraint (https://github.com/cockroachdb/cockroach/issues/31632)")
1179
1180 _, err := db.Exec(`create temporary table defer_test (
1181 id text primary key,
1182 n int not null, unique (n),
1183 unique (n) deferrable initially deferred )`)
1184 require.NoError(t, err)
1185
1186 _, err = db.Exec(`drop function if exists test_trigger cascade`)
1187 require.NoError(t, err)
1188
1189 _, err = db.Exec(`create function test_trigger() returns trigger language plpgsql as $$
1190 begin
1191 if new.n = 4 then
1192 raise exception 'n cant be 4!';
1193 end if;
1194 return new;
1195 end$$`)
1196 require.NoError(t, err)
1197
1198 _, err = db.Exec(`create constraint trigger test
1199 after insert or update on defer_test
1200 deferrable initially deferred
1201 for each row
1202 execute function test_trigger()`)
1203 require.NoError(t, err)
1204
1205 _, err = db.Exec(`insert into defer_test (id, n) values ('a', 1), ('b', 2), ('c', 3)`)
1206 require.NoError(t, err)
1207
1208 var id string
1209 err = db.QueryRow(`insert into defer_test (id, n) values ('e', 4) returning id`).Scan(&id)
1210 assert.Error(t, err)
1211 })
1212}
1213
1214func TestOptionBeforeAfterConnect(t *testing.T) {
1215 config, err := pgx.ParseConfig(os.Getenv("PGX_TEST_DATABASE"))

Callers

nothing calls this directly

Calls 7

skipCockroachDBFunction · 0.70
ExecMethod · 0.65
ScanMethod · 0.65
QueryRowMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected