| From: | Tim Landscheidt <tim(at)tim-landscheidt(dot)de> |
|---|---|
| To: | pgsql-general(at)postgresql(dot)org |
| Subject: | Re: Looping through string constants |
| Date: | 2009-08-12 23:23:47 |
| Message-ID: | m363csty4c.fsf@passepartout.tim-landscheidt.de |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
David Kerr <dmk(at)mr-paradox(dot)net> wrote:
> 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
> echo $a
> done
> ./a.ksh
> a
> b
> c
> d
> e
> Is there some tricky way I can make that happen in postgres?
> (I don't want to put the values in a table =) that would be too easy!)
If you do not want to use arrays, you can always use:
| FOR r IN SELECT a FROM (VALUES ('a'), ('b'), ('c'), ('d'), ('e')) AS t(a) ORDER BY a LOOP
| RAISE NOTICE '%', r.a;
| END LOOP;
Tim
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Chris | 2009-08-12 23:37:25 | Re: Simulate count result are distinct between 8.3 and 8.4 |
| Previous Message | Tom Lane | 2009-08-12 23:19:22 | Re: trouble building pgbench on CentOS 5.3: /usr/bin/ld: cannot find -lpgport |