block transactions in stored procedures

Поиск
Список
Период
Сортировка
От Ghiz x
Тема block transactions in stored procedures
Дата
Msg-id 20060116130444.48434.qmail@web26403.mail.ukl.yahoo.com
обсуждение исходный текст
Ответы Re: block transactions in stored procedures
Список pgsql-novice
 I'd like to write a plperl  stored procedure that inserts data collected from a web form into multiple tables related by means of foreign keys for integral reference's sake.

Each table uses an independent sequence as primary key.

For instance the db consists of tableA and tableB; tableA's primary key is referenced as a foreign key
by one field of tableB.
In order to insert the tableA_id of the latest  inserted row into  the foreign key field referencing to it in tableB I'd retrieve tableA_id from tableA_id_seq  before inserting the new row in both tables as follows (ala plperl):

$sql='select nextval(\'indirizzo_indirizzo_id_seq\');';

$rv = spi_exec_query($sql);

$row = $rv->{rows}[0];

$tableA_id = $row->{nextval};

$sql=insert into tableA($tableA_id,...);

$rv = spi_exec_query($sql);

$sql=insert into tableB(DEFAULT,..,$tableA_id,...);

$rv = spi_exec_query($sql);

Reading through SPI (Server Programming Api) documentation, it seems SPI_execute() runs a single sql statement per call an I myself verified that
spi_exec_query('BEGIN WORK;SELECT nextval(\'indirizzo_indirizzo_id_seq\');COMMIT WORK;') doesn't work.

Apart from my specific problem, my questioning is on how does one enforce a BEGIN WORK;
......

COMMIT WORK;

block transaction within a plperl stored procedure


Any hint or reference to tutorials about this issue would be really appreciated.

Ghiz


Yahoo! Mail: gratis 1GB per i messaggi, antispam, antivirus, POP3

В списке pgsql-novice по дате отправления:

Предыдущее
От: "Christian Hofmann"
Дата:
Сообщение: Re: Help with query
Следующее
От: Andreas Kretschmer
Дата:
Сообщение: Re: Help with query