pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedHow to loop though an array plpgsql?
2+ messages / 2 participants
[nested] [flat]
* How to loop though an array plpgsql?
@ 2005-07-29 23:39 Matthew Schumacher <matt.s@aptalaska.net>
2005-07-30 13:15 ` Re: How to loop though an array plpgsql? Michael Fuhr <mike@fuhr.org>
0 siblings, 1 reply; 2+ messages in thread
From: Matthew Schumacher @ 2005-07-29 23:39 UTC (permalink / raw)
To: pgsql-sql
I need to loop though an input array, but can't figure out how to do it,
the docs aren't really clear on this.
Something like this:
CREATE FUNCTION update (_id INTEGER[])
RETURNS VOID AS
$$
BEGIN
FOR i IN SELECT _id LOOP
INSERT INTO table VALUES (_id[i]);
END LOOP;
END;
$$
LANGUAGE plpgsql;
Anyone know the correct loop syntax?
schu
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: How to loop though an array plpgsql?
2005-07-29 23:39 How to loop though an array plpgsql? Matthew Schumacher <matt.s@aptalaska.net>
@ 2005-07-30 13:15 ` Michael Fuhr <mike@fuhr.org>
0 siblings, 0 replies; 2+ messages in thread
From: Michael Fuhr @ 2005-07-30 13:15 UTC (permalink / raw)
To: Matthew Schumacher <matt.s@aptalaska.net>; +Cc: pgsql-sql
On Fri, Jul 29, 2005 at 03:39:12PM -0800, Matthew Schumacher wrote:
> I need to loop though an input array, but can't figure out how to do it,
> the docs aren't really clear on this.
This comes up from time to time -- search the archives to see past
discussion. Suggestions usually involve array_lower() and array_upper().
http://archives.postgresql.org/
http://www.postgresql.org/docs/8.0/static/functions-array.html
If you're using integers then see also the int_array_enum() function
in the contrib/intagg module.
--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2005-07-30 13:15 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-07-29 23:39 How to loop though an array plpgsql? Matthew Schumacher <matt.s@aptalaska.net>
2005-07-30 13:15 ` Michael Fuhr <mike@fuhr.org>
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