Re: FOR-LOOP durch eine Ergebnismenge

Andreas Kretschmer <[email protected]>
Newsgroups gmane.comp.db.postgresql.german
Message-ID <20130329180532.GA12257@tux>
Martin Spott <[email protected]> wrote:

> 
> CREATE OR REPLACE FUNCTION testproc()
>     RETURNS void
> AS $$
>     DECLARE
>         layer record;
>     BEGIN
>         FOR layer IN SELECT f_table_name FROM geometry_columns WHERE f_table_name LIKE 'clc06_sand'
>         LOOP
>             SELECT * FROM layer;

Dat geht so ned !

Du hast da nun eine Variable namens layer, diese enthält einen TEXT.
Damit frickelst Dir nun einen größeren TEXT zusammen und machts ein
EXECUTE:

execute 'select * from ' || layer || ';';

*untested*


Siehe Doku unter dynamisches SQL



Andreas
-- 
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."   (unknown)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°


-- 
Sent via pgsql-de-allgemein mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-de-allgemein
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.