Help : Update and insert record based on several value in the parameter

Поиск
Список
Период
Сортировка
От Hengky Lie
Тема Help : Update and insert record based on several value in the parameter
Дата
Msg-id CADvRrxOT3G2+LM+pmHQf5kKnC=4SD0Mkm9_J=aJmBdtms0+E7Q@mail.gmail.com
обсуждение исходный текст
Список pgsql-general
Hi,

I want to create a function to update my table (flag='9') and insert new record (flag='0') with the rfidnumber specified in a parameter. 

This parameter may have several value seperated by space (ie. 11 22 33 44)

CREATE OR REPLACE FUNCTION public.fcreate_rfid (
  znumber varchar
)
RETURNS boolean AS
$body$
BEGIN
--update old record which has the same rfid number and flag='0' if exists
update tblrfid set flag='9' where flag='0' and rfidnumber in (znumber);
    
    -- generate new record
insert into tblrfid(tanggal, flag, rfidnumber)
select localtimestamp, '0', regexp_split_to_table(znumber, ' ');
    
     return true;
END;
$body$
LANGUAGE 'plpgsql';

when i called this function using command :

select fcreate_rfid('11 22 33 44');

This function fail to update the old record, but success to insert the new record.

Please help me how to fixed this problem. I know the problem is the update command, but i don't know the correct it. Googling anywhere didn't find a solution.

Thank you

Virus-free. www.avg.com

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

Предыдущее
От: Hengky Lie
Дата:
Сообщение: Help : Update and insert record based on several value in the parameter
Следующее
От: Andrew Gierth
Дата:
Сообщение: Re: Help : Update and insert record based on several value in the parameter