[SQL] Recursive query for Product Tree

2007-04-30 Thread devil live

I have product tree for a product

product_tree table :
product_code, stock_code, amount_ratio
152.001.001,  151.001.001, 1
152.001.001,  150.001.001, 2
151.001.001   150.003.003, 3
151.001.001   150.009.001, 1


I need to write a query with result:

152.001.001,  150.003.003, 1
152.001.001,  150.009.001, 1
152.001.001,  150.001.001, 2


i.e. for 151 we have another node and i do not wanna see 151 here...but its 
ingredients..


it is kind of recursive query how can i write it ? any help?

Thx in advance

_
Spam filtresi ile virüslere karsi en güvenilir koruma, MSN PC Koruma'dan 
geçer. http://www.msn.com.tr/security/



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


[SQL] NEW to plpythonu function?

2007-04-30 Thread David Flegl

Hi,
  may anyone help me with problem how to passed trigger row NEW from 
trigger function in plpgsql to other support function in plpythonu? I've 
tried something like>


CREATE FUNCTION pythfce(arg record)...
CREATE FUNCTION pythfce(arg anyelement)...

but now effect. I'm getting system messages like: plpythonu don't know 
argument type recort, anyelement)


P.S. I would like to have trigger function in plpgsql and supporting 
function in plpythonu, not to join them to plpythonu.


Thankx a lot

David Flegl

---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings


[SQL] Dynamic prepare possible in plpgsql?

2007-04-30 Thread Collin Peters

Is it possible to have a dynamic PREPARE statement in plpgsql?

Something like

PREPARE users_plan ( || 'text, text' || ) AS
INSERT INTO pp_users( || 'col1, col2' || )
VALUES($1, $2);

Regards,
Collin

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


[SQL] "is not distinct from" syntax error?

2007-04-30 Thread Collin Peters

From: http://www.postgresql.org/docs/8.2/static/functions-comparison.html

" The ordinary comparison operators yield null (signifying "unknown")
when either input is null. Another way to do comparisons is with the
IS [ NOT ] DISTINCT FROM construct:

expression IS DISTINCT FROM expression
expression IS NOT DISTINCT FROM expression

For non-null inputs, IS DISTINCT FROM is the same as the <> operator.
However, when both inputs are null it will return false, and when just
one input is null it will return true. Similarly, IS NOT DISTINCT FROM
is identical to = for non-null inputs, but it returns true when both
inputs are null, and false when only one input is null. Thus, these
constructs effectively act as though null were a normal data value,
rather than "unknown"."

However, when I do:
SELECT  1 IS NOT DISTINCT FROM 2

I get "ERROR: syntax error at or near "DISTINCT""

I can do:
SELECT  NOT (1 IS DISTINCT FROM 2)

What is the problem here?

Regards,
Collin

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


Re: [SQL] "is not distinct from" syntax error?

2007-04-30 Thread Tom Lane
"Collin Peters" <[EMAIL PROTECTED]> writes:
> However, when I do:
> SELECT1 IS NOT DISTINCT FROM 2
> I get "ERROR: syntax error at or near "DISTINCT""

> What is the problem here?

Using a pre-8.2 server, likely.

regards, tom lane

---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq


Re: [SQL] Dynamic prepare possible in plpgsql?

2007-04-30 Thread Tom Lane
"Collin Peters" <[EMAIL PROTECTED]> writes:
> Is it possible to have a dynamic PREPARE statement in plpgsql?

Well, you could use plpgsql's EXECUTE to run SQL PREPARE and EXECUTE
commands, but it seems awfully brute-force.  What do you really need
to accomplish here?

regards, tom lane

---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
   choose an index scan if your joining column's datatypes do not
   match