Re: Looping through string constants - Mailing list pgsql-general

From Tom Lane
Subject Re: Looping through string constants
Date
Msg-id 14835.1250118616@sss.pgh.pa.us
Whole thread Raw
In response to Looping through string constants  (David Kerr <dmk@mr-paradox.net>)
Responses Re: Looping through string constants
List pgsql-general
David Kerr <dmk@mr-paradox.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

pgsql-general by date:

Previous
From: Aleksey Tsalolikhin
Date:
Subject: trouble building pgbench on CentOS 5.3: /usr/bin/ld: cannot find -lpgport
Next
From: Tom Lane
Date:
Subject: Re: trouble building pgbench on CentOS 5.3: /usr/bin/ld: cannot find -lpgport