From: Andrew Gierth <andrew@tao11.riddles.org.uk>
To: Hengky Lie <hengkyliwandouw@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Help : Update and insert record based on several value in the parameter
Date: Tue, 29 Jan 2019 13:02:13 +0000
Message-ID: <87pnsfhb97.fsf@news-spur.riddles.org.uk> (raw)
In-Reply-To: <CADvRrxNr0oPprvjvei6Aud5hUGiCpnPU+cHnPrzREXmtn1=0dA@mail.gmail.com>
References: <CADvRrxNr0oPprvjvei6Aud5hUGiCpnPU+cHnPrzREXmtn1=0dA@mail.gmail.com>
>>>>> "Hengky" == Hengky Lie <hengkyliwandouw@gmail.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)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: andrew@tao11.riddles.org.uk, hengkyliwandouw@gmail.com
Subject: Re: Help : Update and insert record based on several value in the parameter
In-Reply-To: <87pnsfhb97.fsf@news-spur.riddles.org.uk>
References: <CADvRrxNr0oPprvjvei6Aud5hUGiCpnPU+cHnPrzREXmtn1=0dA@mail.gmail.com> <87pnsfhb97.fsf@news-spur.riddles.org.uk>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox