Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>>>>> "Hengky" == Hengky Lie <hengkyliwandouw@xxxxxxxxx> writes:

 Hengky> Hi,

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

rfidnumber is stored as text/varchar? if it's something else, change the
suggestions below accordingly.

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

update ... and rfidnumber = any (string_to_array(znumber,' '))

Or, do the split just once:

DECLARE
  z_ids text[] := string_to_array(znumber, ' ');
BEGIN
  update ... where flag='0' and rfidnumber =any (z_ids);
  insert into ...
  select localtimestamp, '0', id from unnest(z_ids) as u(id);

-- 
Andrew (irc:RhodiumToad)




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux