pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephan Szabo <sszabo@megazone23.bigpanda.com>
To: Erwin Ambrosch <erwin.ambrosch@aon.at>
Cc: pgsql-admin@postgresql.org
Subject: Re: pgsql function doesn't work
Date: Wed, 18 Jun 2003 10:23:54 -0700 (PDT)
Message-ID: <20030618102030.W33406-100000@megazone23.bigpanda.com> (raw)
In-Reply-To: <3EF029EE.9040002@aon.at>

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.





view thread (5+ messages)  latest in thread

Message-ID: <20030618102030.W33406-100000@megazone23.bigpanda.com>
Permalink:  ../20030618102030.W33406-100000@megazone23.bigpanda.com/
Also on:    postgresql.org/message-id/20030618102030.W33406-100000@megazone23.bigpanda.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: sszabo@megazone23.bigpanda.com, erwin.ambrosch@aon.at
  Subject: Re: pgsql function doesn't work
  In-Reply-To: <20030618102030.W33406-100000@megazone23.bigpanda.com>
  References: <3EF029EE.9040002@aon.at> <20030618102030.W33406-100000@megazone23.bigpanda.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox