From: | "Richard Sydney-Smith" <richard(at)ibisaustralia(dot)com> |
---|---|
To: | <pgsql-sql(at)postgresql(dot)org> |
Subject: | Test for file exists? |
Date: | 2004-09-20 03:16:47 |
Message-ID: | 002a01c49ec0$4527eb50$630736cb@athlon2000 |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Reiner Dassing | 2004-09-20 07:20:03 | Re: How to check postgres running or not ? |
Previous Message | Arne Stoelck | 2004-09-20 02:33:03 | Re: How to check postgres running or not ? |