Search Postgresql Archives

Re: Return types of a function

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

 



Nalin Bakshi <nbakshi@xxxxxxxxx> 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°


[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