Test for file exists? - Mailing list pgsql-sql

From Richard Sydney-Smith
Subject Test for file exists?
Date
Msg-id 002a01c49ec0$4527eb50$630736cb@athlon2000
Whole thread Raw
In response to Re: How to check postgres running or not ?  (Christopher Browne <cbbrowne@acm.org>)
Responses Re: Test for file exists?
List 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



pgsql-sql by date:

Previous
From: Christopher Browne
Date:
Subject: Re: How to check postgres running or not ?
Next
From: Reiner Dassing
Date:
Subject: Re: How to check postgres running or not ?