https://github.com/jackc/pgx/issues/958
(t *testing.T)
| 1173 | |
| 1174 | // https://github.com/jackc/pgx/issues/958 |
| 1175 | func 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 | |
| 1214 | func TestOptionBeforeAfterConnect(t *testing.T) { |
| 1215 | config, err := pgx.ParseConfig(os.Getenv("PGX_TEST_DATABASE")) |
nothing calls this directly
no test coverage detected