I want to use pgsql to send the command:

Copy sometable from 'sometable.csv';

But only if 'sometable.csv' exists;

If 'sometable.csv' does not exist as an input table I want to continue
the next command.

My full procedure is as follows and any help is greatly appreciated.

Thanks

Richard

CREATE OR REPLACE FUNCTION restore_database(text)
  RETURNS text AS
$BODY$
declare 
tblname record;
cnt record;
tname varchar :='';
tquery varchar :='';
filename varchar :='';

begin
tname := '';
for tblname in select tablename from pg_tables WHERE not(tablename like
'pg_%') and not(tablename like 't_%') 
and not(tablename like '%_list') order by tablename  loop
   raise notice '%',tblname.tablename;
   tquery := 'delete from ' || tblname.tablename ;
   execute tquery;
   filename := '/'||$1||'/'|| lower(tblname.tablename)||'.csv';
   tquery := 'copy ' || tblname.tablename || ' from ' ||
quote_literal(filename);
   execute tquery;
end loop;

return tquery;
end;
$BODY$
  LANGUAGE 'plpgsql' VOLATILE;

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.760 / Virus Database: 509 - Release Date: 10/09/2004
 


---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

               http://archives.postgresql.org

Reply via email to