How to loop though an array plpgsql?

From: Matthew Schumacher <matt(dot)s(at)aptalaska(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: How to loop though an array plpgsql?
Date: 2005-07-29 23:39:12
Message-ID: 42EABE20.6040805@aptalaska.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Kyle Bateman 2005-07-30 04:50:08 bug in information_schema?
Previous Message daq 2005-07-29 18:53:21 Re: CREATE TABLE AS SELECT