Re: Return types of a function

From: Andreas Kretschmer <akretschmer(at)spamfence(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Return types of a function
Date: 2006-02-11 09:39:01
Message-ID: 20060211093901.GC5064@KanotixBox
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Nalin Bakshi <nbakshi(at)bisil(dot)com> schrieb:

>
> Hi!
> I have postgres installed in my machine and have a simple task to do.
> Step1) Fetch all the tables in the Database with name staerting with "AA"
> Step2) On each table you get fire a simple SQL query:
> select * from <tablename>;
> Step3) Right these into a flat file.
> I have to carry out all these steps using a prcedure/function.

,----
| create or replace function do_select(varchar) returns varchar as $$
| declare
| tab record;
| sql varchar;
| file varchar;
| begin
| for tab in select table_name from information_schema.tables where table_name ~ $1 loop
| file := quote_literal('/tmp/' || tab.table_name);
| sql := 'copy ' || tab.table_name || ' to ' || file || '; ';
| raise notice '%', sql;
| execute sql;
| end loop;
| return 'ready';
| end;
| $$ language plpgsql;
`----

test=# select do_select('^foo*');
NOTICE: copy foo1 to '/tmp/foo1';
NOTICE: copy foo to '/tmp/foo';
do_select
-----------
ready
(1 row)

HTH, 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." (unknow)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Luca Pireddu 2006-02-11 09:49:09 Re: Database Comparison tool?
Previous Message Michael Fuhr 2006-02-11 07:35:34 Re: Limiting with a left outer join