X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id C80A430D183 for ; Wed, 18 Jun 2003 17:24:13 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 93590-06 for ; Wed, 18 Jun 2003 14:24:03 -0300 (ADT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) by svr1.postgresql.org (Postfix) with ESMTP id D251130DCD8 for ; Wed, 18 Jun 2003 14:24:02 -0300 (ADT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 38EB3D602; Wed, 18 Jun 2003 10:23:55 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 2E98C5C0B; Wed, 18 Jun 2003 10:23:55 -0700 (PDT) Date: Wed, 18 Jun 2003 10:23:54 -0700 (PDT) From: Stephan Szabo To: Erwin Ambrosch Cc: Subject: Re: pgsql function doesn't work In-Reply-To: <3EF029EE.9040002@aon.at> Message-ID: <20030618102030.W33406-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Archive-Number: 200306/234 X-Sequence-Number: 9225 On Wed, 18 Jun 2003, Erwin Ambrosch wrote: > Hi, > > the function bellow is created successfully, but executing it forces the > following error message: > > WARNING: Error occurred while executing PL/pgSQL function > drop_table_if_exists > WARNING: line 5 at select into variables > ERROR: parser: parse error at or near "$1" at character 34 > > > CREATE OR REPLACE FUNCTION drop_table_if_exists(TEXT) RETURNS BOOLEAN AS ' > DECLARE > rec RECORD; > BEGIN > > SELECT INTO rec off_mitarbeiter_id FROM $1; You can't do this in plpgsql without some form of EXECUTE. > IF FOUND THEN > EXECUTE ''DROP TABLE'' || '' '' || $1; > RETURN true; > END IF; > > RETURN false; > > END;' > LANGUAGE 'plpgsql'; However, AFAICS this will error if the table doesn't exist (selecting from a non-existant table) rather than do nothing which I'm guessing was the point since otherwise you could do the drop without the function. You might want to consider querying the system catalogs instead.