Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql General > Results of stor...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 15619 of 17437
Post > Topic >>

Results of stored procedures in WHERE clause

by Gordon <gordon.mcvey@[EMAIL PROTECTED] > May 20, 2008 at 09:02 AM

I have a table representing tree structures of pages on a website.
they have an itm_id column (integer key) and an itm_parent column
(pointer to item's parent node).  Any item with an itm_parent of 0 is
a root node, representing a website.  Anything with a non-zero parent
is a non-root node representing a folder or do***ent in a website.

I need to be able to do queries that restrict my result set to items
belonging to a specified site and ignore all nodes that belong to
different sites.  To determine the ID of the site an item belongs to I
wrote a stored procedure:

CREATE OR REPLACE FUNCTION cms.getroot(node integer)
  RETURNS integer AS
$BODY$DECLARE
	thisnode	integer := node;
	thisparent	integer	:= node;
BEGIN
	WHILE thisparent != 0 LOOP
		SELECT itm_id, itm_parent
		INTO thisnode, thisparent
		FROM cms.cms_items
		WHERE itm_id = thisparent;
	END LOOP;
	RETURN thisnode;
END;
$BODY$
  LANGUAGE 'plpgsql' STABLE
  COST 100;

This returns the ID of the root node for non-root nodes, the node's
own ID for root-nodes and NULL for invalid IDs.

I'm writing a query to do do***ent searching (the version given is
simplified to the problem in hand).

SELECT cms_v_items.* ,
getroot (cms_v_items.itm_id) AS itm_root
FROM cms_v_items
WHERE itm_root = ?;

I was hoping this query would return a set of items that had the same
root node.  Instead it throws an error, column itm_root does not
exist.

I'm obviously doing something wrong here, but what?
 




 4 Posts in Topic:
Results of stored procedures in WHERE clause
Gordon <gordon.mcvey@[  2008-05-20 09:02:36 
Re: Results of stored procedures in WHERE clause
Gordon <gordon.mcvey@[  2008-05-21 01:34:34 
Re: Results of stored procedures in WHERE clause
justinp@[EMAIL PROTECTED]  2008-05-22 18:06:17 
Re: Results of stored procedures in WHERE clause
Jon.Roberts@[EMAIL PROTEC  2008-05-23 08:23:16 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 12:27:07 CST 2008.