Search Postgresql Archives

Re: Isolating a record column from a PL-Pgsql function call ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



And it's a bit more complicated at that. Here's why....

I discovered that I can refer to the function as a relation in the from clause...

  select y.col1 from my_plpgsql_fn(789) y

but I need to pass the function something from outside, sort of like...

  select x.col_a, y.col1
  from mytable x, my_plpgsql_fn(a.val) y
  where x.col_b = 'foo';

When I try this one, I get a "ERROR Function expression in FROM cannot refer to other relations of same query level"


I could accomplish what I need to because Im actually doing all this in the Perl/DBI.  And in Perl, I can just run the "x" query in a loop, then the "my_plpgsql_fn" call inside the loop.  This will accomplish the same thing, but it'll be 2 queries instead of one (and it'll be far from elegant!)

-dave 





-----Original Message-----
From: pgsql-general-owner@xxxxxxxxxxxxxx [mailto:pgsql-general-owner@xxxxxxxxxxxxxx] On Behalf Of Gauthier, Dave
Sent: Tuesday, December 16, 2008 3:03 PM
To: Andreas Kretschmer; pgsql-general@xxxxxxxxxxxxxx
Subject: Re:  Isolating a record column from a PL-Pgsql function call ?

The example I gave was overly simplistic.  I actually want to look at more than one of the columns in the returned record, so rewritting it to return an int won't address the need for the other columns.  And no, it does not return a set/array of records.  It returns just one record.  

If I run the function outside of a query, it returns something like...

"(myvcharval1,myvcharval2,myintval)"

Notice the parens, the commas and the lack of single quotes around the "myvcharval(x)" values.

I suppose I could do some funky string dissection with this, but I was wondering if there was something more straignt-forward.

-dave

-----Original Message-----
From: pgsql-general-owner@xxxxxxxxxxxxxx [mailto:pgsql-general-owner@xxxxxxxxxxxxxx] On Behalf Of Andreas Kretschmer
Sent: Tuesday, December 16, 2008 2:51 PM
To: pgsql-general@xxxxxxxxxxxxxx
Subject: Re:  Isolating a record column from a PL-Pgsql function call ?

Gauthier, Dave <dave.gauthier@xxxxxxxxx> schrieb:

> Hi:
> 
>  
> 
> I have a PL-Pgsql function that returns a record of a type that have 4 elements
> (columns).  Let's say the first element/column is called "id_num".  Is there a
> way I can specify the id_num element of the record returned from iside a query?
> 
>  
> 
> For example, select col1 from thetable where my_plpgsql_fn(col2).id_num = 123;

I think, you should rewrite your function to hand over the id_num as
additional parameter. But i'm not sure if i understand you corrently. Is
this a setof-returning function?

Please, show us your real function, maybe someone can help you more.




Andreas
-- 
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."   (unknown)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux