Re: dblink inside plpgsql function

From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Loredana Curugiu" <loredana(dot)curugiu(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org, pgsql-sql(at)postgresql(dot)org
Subject: Re: dblink inside plpgsql function
Date: 2007-07-03 09:13:42
Message-ID: 162867790707030213h7c81e498p1b5f9d7c9cf1cc9b@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice pgsql-sql

Hello

Every SELECT statement in PL/pgSQL have to be forward to variables. In
plpgsql you can you use select only like

select into variables columns from ...

propably better version is (i haven't installed dblink and can't to test it)

CREATE OR REPLACE FUNCTION GetReminderServices( varchar ) RETURNS
SETOF reminder_services AS'
DECLARE r record;
BEGIN
PERFORM dblink_connect(''dbname=''||$1);
FOR r IN SELECT * FROM dblink(''SELECT * FROM reminder_services'')
AS reminder_services( uid INT,
theme_uid INT,
activity_MT_amount INT,
activity_min_days INT,
activity_max_months INT,
inactivity_days INT,
limit_reminders INT,
limit_months INT,
scanning_time TIMESTAMP WITH TIME ZONE,
reminder_time TIMESTAMP WITH TIME ZONE,
message TEXT)
LOOP
RETURN NEXT r;
END LOOP;
PERFORM dblink_disconnect($1);
RETURN
END;
' LANGUAGE plpgsql;

regards
Pavel

2007/7/3, Loredana Curugiu <loredana(dot)curugiu(at)gmail(dot)com>:
> Hi everybody,
>
> I created the following function:
>
> CREATE OR REPLACE FUNCTION GetReminderServices( varchar ) RETURNS SETOF
> reminder_services AS'
> BEGIN
> SELECT dblink_connect(''dbname=''||$1);
> SELECT * FROM dblink(''SELECT * FROM reminder_services'')
> AS reminder_services( uid INT,
> theme_uid INT,
> activity_MT_amount
> INT,
> activity_min_days
> INT,
> activity_max_months
> INT,
> inactivity_days INT,
> limit_reminders INT,
> limit_months INT,
> scanning_time
> TIMESTAMP WITH TIME ZONE,
> reminder_time
> TIMESTAMP WITH TIME ZONE,
> message TEXT);
> SELECT dblink_disconnect($1);
> RETURN;
> END;
> ' LANGUAGE plpgsql;
>
> When I call this function as SELECT * FROM GetReminderServices('eu');
> I get the following errors:
> ERROR: query has no destination for result data
> HINT: If you want to discard the results of a SELECT, use PERFORM instead.
> CONTEXT: PL/pgSQL function "getreminderservices" line 2 at SQL statement
>
> Does somebody know which is the problem?
>
>
> Best,
> Loredana
>
>
>
>

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Bart Degryse 2007-07-03 09:45:53 Re: dblink inside plpgsql function
Previous Message Loredana Curugiu 2007-07-03 09:02:54 dblink inside plpgsql function

Browse pgsql-sql by date

  From Date Subject
Next Message Bart Degryse 2007-07-03 09:45:53 Re: dblink inside plpgsql function
Previous Message Loredana Curugiu 2007-07-03 09:02:54 dblink inside plpgsql function