Re: DBLink: interesting issue

From: Joe Conway <mail(at)joeconway(dot)com>
To: Oleg Lebedev <oleg(dot)lebedev(at)waterford(dot)org>, pgsql-general(at)postgresql(dot)org
Subject: Re: DBLink: interesting issue
Date: 2002-09-24 03:36:35
Message-ID: 3D8FDDC3.40901@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Oleg Lebedev wrote:
> Ok, here are all the files.
>

I'm now seeing the problem you reported. It is a bug in the new table function
code. Basically, you are trying to do this:

DELETE FROM tablea
WHERE NOT EXISTS
(
SELECT remoteid
FROM
(
SELECT remoteid
FROM dblink('hostaddr=1.23.45.6 port=5432 dbname=webspec user=user
password=pass',
'SELECT objectid FROM tablea WHERE objectid = ' ||
tablea.objectid)
AS dblink_rec(remoteid int8)
) AS t1
);

But if you try:

SELECT remoteid
FROM
(
SELECT remoteid
FROM dblink('hostaddr=1.23.45.6 port=5432 dbname=webspec user=user
password=pass',
'SELECT objectid FROM tablea WHERE objectid = ' ||
tablea.objectid)
AS dblink_rec(remoteid int8)
) AS t1;

you'll get:

ERROR: FROM function expression may not refer to other relations of same
query level

which is what you're supposed to get. Apparently the error is not getting
generated as it should when this query is run as a subquery.

What you should actually be doing is:

DELETE FROM tablea
WHERE NOT EXISTS
(
SELECT remoteid
FROM dblink('hostaddr=1.23.45.6 port=5432 dbname=webspec user=user
password=pass',
'SELECT objectid FROM tablea WHERE objectid = ' ||
tablea.objectid)
AS dblink_rec(remoteid int8)
);
DELETE 0

This should make your function work on 7.3beta, but I still need to track down
a fix for the bug. Thanks for the report!

Joe

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2002-09-24 03:37:45 Re: [GENERAL] CURRENT_TIMESTAMP
Previous Message Tom Lane 2002-09-24 03:35:13 Re: [GENERAL] CURRENT_TIMESTAMP

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2002-09-24 03:37:45 Re: [GENERAL] CURRENT_TIMESTAMP
Previous Message Tom Lane 2002-09-24 03:35:13 Re: [GENERAL] CURRENT_TIMESTAMP