Test for file exists?
От | Richard Sydney-Smith |
---|---|
Тема | Test for file exists? |
Дата | |
Msg-id | 002a01c49ec0$4527eb50$630736cb@athlon2000 обсуждение исходный текст |
Ответ на | Re: How to check postgres running or not ? (Christopher Browne <cbbrowne@acm.org>) |
Ответы |
Re: Test for file exists?
|
Список | 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 по дате отправления: