pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
URGENT:  Using function inside query
2+ messages / 2 participants
[nested] [flat]

* URGENT:  Using function inside query
@ 2005-01-18 20:51  Bradley Miller <bmiller@nuvio.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Bradley Miller @ 2005-01-18 20:51 UTC (permalink / raw)
  To: pgsql-sql

I need some help on the following problem.  I have an account info 
table that has a hierarchy of accounts.  The grouping goes from end 
user to organization to reseller.  I have a PL/SQL function written 
that gives me the tree, so I just whittle it down by selecting the one 
id for a reseller:

select account_id from roll_account(1186) where hierarchy_type_id = 2


The problem is I have data like this:

account id    name

1    Company A
2    Company B
3    Company C
4    Person 1 (in Company A)
5    Person 2 (in Company A)

If I pass it the number of let's say Person 2 -- the above query wold 
give me the account id of 1.    How can I do a query using that 
function so that it automatically inserts the account_id to show the 
"rolled up" account id ?


Bradley Miller
NUVIO CORPORATION
Phone: 816-444-4422 ext. 6757
Fax: 913-498-1810
http://www.nuvio.com
bmiller@nuvio.com

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: URGENT:  Using function inside query
@ 2005-01-19 06:39  Michael Fuhr <mike@fuhr.org>
  parent: Bradley Miller <bmiller@nuvio.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Michael Fuhr @ 2005-01-19 06:39 UTC (permalink / raw)
  To: Bradley Miller <bmiller@nuvio.com>; +Cc: pgsql-sql

On Tue, Jan 18, 2005 at 02:51:01PM -0600, Bradley Miller wrote:

> select account_id from roll_account(1186) where hierarchy_type_id = 2 
> 
> The problem is I have data like this: 
> 
> account id    name     
> 
> 1    Company A   
> 2    Company B 
> 3    Company C 
> 4    Person 1 (in Company A) 
> 5    Person 2 (in Company A) 
> 
> If I pass it the number of let's say Person 2 -- the above query wold 
> give me the account id of 1.    How can I do a query using that 
> function so that it automatically inserts the account_id to show the 
> "rolled up" account id ?  

I'm not sure I follow -- what account_id are you trying to insert
and where are you trying to insert it?  Do you want something like
this?

SELECT account_id
FROM roll_account(
  (SELECT account_id FROM account_info WHERE name = 'Person 2')
)
WHERE hierarchy_type_id = 2;

If that's not what you're after then please provide an example of
the kind of query you'd like to make and what results you expect.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2005-01-19 06:39 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-01-18 20:51 URGENT:  Using function inside query Bradley Miller <bmiller@nuvio.com>
2005-01-19 06:39 ` Michael Fuhr <mike@fuhr.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox