X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 1116B329C6B for ; Mon, 20 Sep 2004 04:16:27 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 64902-06 for ; Mon, 20 Sep 2004 03:16:21 +0000 (GMT) Received: from gizmo07bw.bigpond.com (gizmo07bw.bigpond.com [144.140.70.42]) by svr1.postgresql.org (Postfix) with SMTP id 7D4AF329C65 for ; Mon, 20 Sep 2004 04:16:19 +0100 (BST) Received: (qmail 3013 invoked from network); 20 Sep 2004 03:16:14 -0000 Received: from unknown (HELO BWMAM17.bigpond.com) (144.135.24.116) by gizmo07bw.bigpond.com with SMTP; 20 Sep 2004 03:16:14 -0000 Received: from wtpp-p-203-54-7-99.prem.tmns.net.au ([203.54.7.99]) by BWMAM17.bigpond.com(MAM REL_3_4_2a 279/75340266) with SMTP id 75340266; Mon, 20 Sep 2004 13:16:14 +1000 From: "Richard Sydney-Smith" To: Subject: Test for file exists? Date: Mon, 20 Sep 2004 11:16:47 +0800 Message-ID: <002a01c49ec0$4527eb50$630736cb@athlon2000> MIME-Version: 1.0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2627 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 In-Reply-To: Importance: Normal X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200409/151 X-Sequence-Number: 18997 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