Thread: Return types of a function

Return types of a function

From
"Nalin Bakshi"
Date:
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.
 
The function would be called by a trigger. Now i need to know how to make a postgres function for that.
 
My problem: My experience with database is almost 5 days and I can't seem to understand the documentation, like how to catch the return value. How to run the procedure for testing without firing the trigger. So could anyone help me with that.
 
Regards,
Nalin.

Re: Return types of a function

From
Andreas Kretschmer
Date:
Nalin Bakshi <nbakshi@bisil.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°