dbTalk Databases Forums  

[BUGS] BUG #2123: join between stored procedures

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] BUG #2123: join between stored procedures in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Konstantin S. Zhinko [tIT]
 
Posts: n/a

Default [BUGS] BUG #2123: join between stored procedures - 12-27-2005 , 08:44 AM







The following bug has been logged online:

Bug reference: 2123
Logged by: Konstantin S. Zhinko [tIT]
Email address: k.zhinko (AT) grape (DOT) ru
PostgreSQL version: 8.1.0
Operating system: CentOS 3.5
Description: join between stored procedures
Details:

Hi all!

I have a very big problem...

Here the code:

/*SQL START*/

CREATE TABLE "public"."test_data" (
"id" INTEGER NOT NULL,
"type" INTEGER NOT NULL,
"short_text" VARCHAR(255),
CONSTRAINT "test_data_pkey" PRIMARY KEY("id")
) WITH OIDS;

CREATE TYPE "public"."ret_id" AS (
"id" INTEGER
);

CREATE TYPE "public"."test" AS (
"id" INTEGER,
"type" INTEGER,
"info" VARCHAR(255)
);

CREATE OR REPLACE FUNCTION "public"."get_obj_list" () RETURNS SETOF
"public"."ret_id" AS
$body$
declare
ret ret_id;
begin

for ret in select test_data.id from test_data
loop

return next ret;

end loop;

end;
$body$
LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;

CREATE OR REPLACE FUNCTION "public"."get_obj" (id integer) RETURNS
"public"."test" AS
$body$
declare
ret test;
in_id alias for $1;

begin

select * from test_data a into ret where a.id=in_id;
return ret;

end;
$body$
LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;

/*SQL END*/

It is ok, but when I try to join these procedures, server responses error

/*SQL START*/
SELECT b.*
FROM get_obj_list a
LEFT JOIN get_obj(a.id) b ON 1=1
/*SQL END*/

Error: relation "a" does not exists.

Why it's so?

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] BUG #2123: join between stored procedures - 12-27-2005 , 09:16 AM






"Konstantin S. Zhinko [tIT]" <k.zhinko (AT) grape (DOT) ru> writes:
Quote:
SELECT b.*
FROM get_obj_list a
LEFT JOIN get_obj(a.id) b ON 1=1
Error: relation "a" does not exists.
This is not a bug. You cannot make use of values from one <table
reference> inside the definition of another <table reference>.
So the reference "a.id" is taken to be to a real table named "a",
not to the "a" alias elsewhere in the query.

You could do something like

SELECT (get_obj(id)).* FROM get_obj_list();

instead.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.