Re: Looping through string constants

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: David Kerr <dmk(at)mr-paradox(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Looping through string constants
Date: 2009-08-12 23:10:16
Message-ID: 14835.1250118616@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

David Kerr <dmk(at)mr-paradox(dot)net> writes:
> I'd like to loop through a group of constant string values using plpgsql
> The best analog i can think of would be in a shell script
> #!/usr/bin/ksh

> for a in a b c d e; do

Use VALUES?

regression=# create function foo() returns int as $$
regression$# declare s int := 0;
regression$# r record;
regression$# begin
regression$# for r in values (1),(2),(3),(4) loop
regression$# s := s + r.column1;
regression$# end loop;
regression$# return s;
regression$# end$$ language plpgsql;
CREATE FUNCTION
regression=# select foo();
foo
-----
10
(1 row)

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2009-08-12 23:19:22 Re: trouble building pgbench on CentOS 5.3: /usr/bin/ld: cannot find -lpgport
Previous Message Aleksey Tsalolikhin 2009-08-12 23:05:34 trouble building pgbench on CentOS 5.3: /usr/bin/ld: cannot find -lpgport