plpgsql function and constraints
От | Jakub Ouhrabka |
---|---|
Тема | plpgsql function and constraints |
Дата | |
Msg-id | Pine.LNX.4.33.0108302037470.9002-100000@u-pl0 обсуждение исходный текст |
Ответ на | bug in hash indexes??? (Jakub Ouhrabka <jouh8664@ss1000.ms.mff.cuni.cz>) |
Список | pgsql-general |
hi, i have table1 and table2. in table1 there is a foreign key referencing id in table2. i'd like to do something like this: CREATE FUNCTION foo() RETURNS INTEGER AS ' DECLARE BEGIN UPDATE table1 SET not_key = 100; DELETE FROM table1; DELETE FROM table2; RETURN 0; END; ' LANGUAGE 'plpgsql'; when i run select foo(); i always get: ERROR: <unnamed> referential integrity violation - key referenced from table1 not found in table2 (i think that's because constraints are checked at the end of statement and this function is treated as one statement... or am i wrong?) when i try it in psql as separate commands in one transaction it's ok: BEGIN; UPDATE table1 SET not_key = 100; DELETE FROM table1; DELETE FROM table2; COMMIT; is there any way to do something like this in plpgsql function? thanks in advance, kuba
В списке pgsql-general по дате отправления: