Re: possible INSERT bug

Поиск
Список
Период
Сортировка
От Mathew Frank
Тема Re: possible INSERT bug
Дата
Msg-id 003f01c2a27a$6da7ab90$0a00a8c0@dax
обсуждение исходный текст
Ответы Re: possible INSERT bug  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-bugs
i have the following utility function, which I use to easily return the OID
 of an the new row created by an INSERT query:
 ---
 CREATE FUNCTION insert_record_return_oid(text) RETURNS int4 AS
 ' DECLARE
     s_query ALIAS FOR $1;
     oid int4;
 BEGIN
     EXECUTE s_query;
     GET DIAGNOSTICS oid = RESULT_OID;
     RETURN oid;
 END;
 ' LANGUAGE 'plpgsql' with (ISSTRICT);
 ---

 Which correctly returns the OID of the inserted row.
 usage example:
 ---
 insert_record_return_oid('insert into sys_states (s_state) values(''po'')
 ');
 ---

 However, if I get tricky, and imbed this into a select to return the
 inserted row, I get an error:
 ---
 select * from sys_states
 where oid= insert_record_return_oid('insert into sys_states (s_state)
 values(''po'') ');
---
 "Cannot insert duplicate key" and the insert query never happens.


 This is not a problem - I just do things another way, but I was wondering
 what caused this?

 Cheers,
 Mathew

 postgresql 7.2, btw

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

Предыдущее
От: Ocke Janssen
Дата:
Сообщение: Re: OpenOffice loops calling SQLForeignKeys
Следующее
От: Tom Lane
Дата:
Сообщение: Re: possible INSERT bug