dbTalk Databases Forums  

joining table with table function on parameter in 8.4

comp.databases.postgresql comp.databases.postgresql


Discuss joining table with table function on parameter in 8.4 in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Pavel Chudnovskyy
 
Posts: n/a

Default joining table with table function on parameter in 8.4 - 01-27-2010 , 06:04 AM






Hi, is it possible to join a table/view with table function, which has
parameters?

Something like

select
u.*,
func_result.*
from users u
left join func_get_some_user_data(u.id) func_result on 1=1

the problem is, i cannot reference u.id field in function call.
"There is an entry for table "u", but it cannot be referenced from this
part of the query"

func_get_some_user_data is a table function returning set of record
(i know i skipped the part, that describes the record)

Reply With Quote
  #2  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: joining table with table function on parameter in 8.4 - 01-28-2010 , 07:32 AM






Pavel Chudnovskyy wrote:
Quote:
Hi, is it possible to join a table/view with table function, which has parameters?

Something like

select
u.*,
func_result.*
from users u
left join func_get_some_user_data(u.id) func_result on 1=1

the problem is, i cannot reference u.id field in function call.
"There is an entry for table "u", but it cannot be referenced from this part of the query"

func_get_some_user_data is a table function returning set of record
(i know i skipped the part, that describes the record)
The way you wrote it it does not make much sense:

A join between two tables is a join of all rows in one
table with all rows in another table.

What would be that second table in your case?

Maybe (tell me if I am wrong) what you really want is to join
only a single row of the "users" table with the function result
and get a UNION of all such joins for all rows of the first table.

I don't think that you can do that with a single SQL statement -
what I would do is write a table function that loops over the
"users" table.

If I misunderstood you, maybe you can post a test case with
a table, a function and what the result should look like.

Yours,
Laurenz Albe

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.