pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedpgsql function doesn't work
5+ messages / 4 participants
[nested] [flat]
* pgsql function doesn't work
@ 2003-06-18 08:59 Erwin Ambrosch <erwin.ambrosch@aon.at>
0 siblings, 1 reply; 5+ messages in thread
From: Erwin Ambrosch @ 2003-06-18 08:59 UTC (permalink / raw)
To: pgsql-admin
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;
IF FOUND THEN
EXECUTE ''DROP TABLE'' || '' '' || $1;
RETURN true;
END IF;
RETURN false;
END;'
LANGUAGE 'plpgsql';
select drop_table_if_exists('off_jahres_abr_2003');
If I hardcode the table name istead of using $1, everything works fine.
Please help.
Thanx Erwin
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: pgsql function doesn't work
@ 2003-06-18 17:23 Stephan Szabo <sszabo@megazone23.bigpanda.com>
parent: Erwin Ambrosch <erwin.ambrosch@aon.at>
0 siblings, 1 reply; 5+ messages in thread
From: Stephan Szabo @ 2003-06-18 17:23 UTC (permalink / raw)
To: Erwin Ambrosch <erwin.ambrosch@aon.at>; +Cc: pgsql-admin
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.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: pgsql function doesn't work
@ 2003-06-20 16:12 Mel Jamero <mel@gmanmi.tv>
parent: Stephan Szabo <sszabo@megazone23.bigpanda.com>
0 siblings, 0 replies; 5+ messages in thread
From: Mel Jamero @ 2003-06-20 16:12 UTC (permalink / raw)
To: 'Erwin Ambrosch' <erwin.ambrosch@aon.at>; +Cc: pgsql-admin
taking queue from Stephan, this would achieve what you want to do though it
i don't find it too 'neat':
DROP FUNCTION drop_table_if_exists(TEXT);
CREATE FUNCTION drop_table_if_exists(TEXT) RETURNS BOOLEAN AS '
DECLARE
str_tmp text;
BEGIN
SELECT INTO str_tmp tablename FROM pg_tables WHERE tablename = $1;
IF FOUND THEN
EXECUTE ''DROP TABLE'' || '' '' || $1;
RETURN true;
END IF;
RETURN false;
END;'
LANGUAGE 'plpgsql';
HTH.
--
Mel Jamero
-----Original Message-----
From: pgsql-admin-owner@postgresql.org
[mailto:pgsql-admin-owner@postgresql.org]On Behalf Of Stephan Szabo
Sent: Thursday, June 19, 2003 1:24 AM
To: Erwin Ambrosch
Cc: pgsql-admin@postgresql.org
Subject: Re: [ADMIN] pgsql function doesn't work
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.
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend
^ permalink raw reply [nested|flat] 5+ messages in thread
* FW: pgsql function doesn't work
@ 2003-06-23 12:25 Mel Jamero <mel@gmanmi.tv>
0 siblings, 1 reply; 5+ messages in thread
From: Mel Jamero @ 2003-06-23 12:25 UTC (permalink / raw)
To: pgsql-admin
I don't understand this. Can anybody translate?
Thanks.
-----Original Message-----
From: grzegorz.przezdziecki@crn.pl [mailto:grzegorz.przezdziecki@crn.pl]
Sent: Friday, June 20, 2003 11:51 PM
To: mel@gmanmi.tv
Subject: Re: [ADMIN] pgsql function doesn't work
Witam
Jestem na urlopie (nie czytam maili).
Wracam 30 czerwca, zastêpuje mnie Adam Wojtkiewicz.
Adres adam.wojtkiewicz@lupus.pl
Pozdrawiam
Grzegorz PrzeŸdziecki
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: FW: pgsql function doesn't work
@ 2003-06-23 12:30 Ian Barwick <barwick@gmx.net>
parent: Mel Jamero <mel@gmanmi.tv>
0 siblings, 0 replies; 5+ messages in thread
From: Ian Barwick @ 2003-06-23 12:30 UTC (permalink / raw)
To: mel@gmanmi.tv; pgsql-admin
On Monday 23 June 2003 14:25, Mel Jamero wrote:
> I don't understand this. Can anybody translate?
>
> Thanks.
I've had this one before. It's a "I'm out of the office"-type
autoresponder. According to my trusty Polish-German
dictionary (always have one to hand ;-) "urlopie" means
"holiday". I would contact Adam Wojtkiewicz if you have any
more detailed questions ;-)
Ian Barwick
barwick@gmx.net
> -----Original Message-----
> From: grzegorz.przezdziecki@crn.pl [mailto:grzegorz.przezdziecki@crn.pl]
> Sent: Friday, June 20, 2003 11:51 PM
> To: mel@gmanmi.tv
> Subject: Re: [ADMIN] pgsql function doesn't work
>
>
> Witam
>
> Jestem na urlopie (nie czytam maili).
> Wracam 30 czerwca, zastêpuje mnie Adam Wojtkiewicz.
> Adres adam.wojtkiewicz@lupus.pl
>
> Pozdrawiam
> Grzegorz PrzeŸdziecki
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faqs/FAQ.html
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2003-06-23 12:30 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-06-18 08:59 pgsql function doesn't work Erwin Ambrosch <erwin.ambrosch@aon.at>
2003-06-18 17:23 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
2003-06-20 16:12 ` Mel Jamero <mel@gmanmi.tv>
2003-06-23 12:25 FW: pgsql function doesn't work Mel Jamero <mel@gmanmi.tv>
2003-06-23 12:30 ` Ian Barwick <barwick@gmx.net>
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