Search Postgresql Archives

Re: Looping through string constants

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



David Kerr <dmk@xxxxxxxxxxxxxx> 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

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux