From: | Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk> |
---|---|
To: | Hengky Lie <hengkyliwandouw(at)gmail(dot)com> |
Cc: | pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: Help : Update and insert record based on several value in the parameter |
Date: | 2019-01-29 13:02:13 |
Message-ID: | 87pnsfhb97.fsf@news-spur.riddles.org.uk |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
>>>>> "Hengky" == Hengky Lie <hengkyliwandouw(at)gmail(dot)com> 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)
From | Date | Subject | |
---|---|---|---|
Next Message | Pavel Stehule | 2019-01-29 13:02:23 | Re: Help : Update and insert record based on several value in the parameter |
Previous Message | Hengky Lie | 2019-01-29 12:55:27 | Help : Update and insert record based on several value in the parameter |