Re: [HACKERS] Hirarchical queries a la Oracle. Patch.

2002-11-28 Thread Tom Lane
Hannu Krosing <[EMAIL PROTECTED]> writes:
> On Thu, 2002-11-28 at 17:34, Evgen Potemkin wrote:
>> understanding SQL99 draft is a bit more difficult than i thought :)

> You might also try to get DB2 installed somewhere (IIRC IBM gives out 
> limited time developer copies).

Even without DB2 installed, you can read the documentation for it on the
web.  There's quite a lot of useful info in IBM's docs.  For example
http://nscpcw.physics.upenn.edu/db2_docs/db2s0/withsel.htm
and the example starting at
http://nscpcw.physics.upenn.edu/db2_docs/db2s0/db2s0446.htm

(The docs are probably also readable directly from IBM, but this is the
first copy I found by googling...)

regards, tom lane

---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly



Re: [HACKERS] Hirarchical queries a la Oracle. Patch.

2002-11-28 Thread Hannu Krosing
On Thu, 2002-11-28 at 17:34, Evgen Potemkin wrote:
> thanks, it's VERY helpful.
> understanding SQL99 draft is a bit more difficult than i thought :)

You might also try to get DB2 installed somewhere (IIRC IBM gives out 
limited time developer copies).

It implements at least the basic recursive query (without requiring the word RECURSIVE 
:)

> 
> --
> Hannu

---(end of broadcast)---
TIP 6: Have you searched our list archives?

http://archives.postgresql.org



Re: [HACKERS] Hirarchical queries a la Oracle. Patch.

2002-11-28 Thread Evgen Potemkin
thanks, it's VERY helpful.
understanding SQL99 draft is a bit more difficult than i thought :)

regards,

---
.evgen

On 27 Nov 2002, Hannu Krosing wrote:

> I attach a railroad diagram of SQL99 "WITH RECURSIVE" and a diff against
> mid-summer gram.y which implements half of SQL99 _syntax_ (just the WITH
> {RECURSIVE} part, SEARCH (tree search order order) and CYCLE (recursion
> control) clauses are missing).
>


---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])



Re: [HACKERS] Hirarchical queries a la Oracle. Patch.

2002-11-26 Thread Hannu Krosing
Evgen Potemkin kirjutas R, 22.11.2002 kell 15:57:
> Hi there!
> 
> Patch is posted to pgsql-patches. docs inside.

It would of course be nice to support both Oracle and ISO/ANSI syntaxes,
but I'm afraid that the (+) may clash with our overloadable operators
feature.

> SQL 99 version will be later.

I attach a railroad diagram of SQL99 "WITH RECURSIVE" and a diff against
mid-summer gram.y which implements half of SQL99 _syntax_ (just the WITH
{RECURSIVE} part, SEARCH (tree search order order) and CYCLE (recursion
control) clauses are missing).

WITH clause seems to be quite useful in its own right as well, not just
for recursive queries, so I guess that someone with good knwledge of
postgresql internals could get plain WITH working quite fast -

The main difference between subqueries defined in WITH clause and in
FROM clause is that while subqueries in FROM don't see each other in
their namespaces, the ones in WITH either see all preceeding ones (plain
with) or just all in WITH clause (WITH RECURSIVE)

--
Hannu





<>276a277,285
> 
> /* WITH CLAUSE */
> 
> %typeopt_recursive
> %type   with_list_element
> %type   with_list
> 
> /* /WITH CLAUSE */
> 
374c383,387
<   READ, REAL, REFERENCES, REINDEX, RELATIVE, RENAME, REPLACE,
---
>   READ, REAL,
>   
>   RECURSIVE,
>   
>   REFERENCES, REINDEX, RELATIVE, RENAME, REPLACE,
4023,4024c4036,4037
< SelectStmt: select_no_parens  %prec UMINUS
<   | select_with_parens%prec UMINUS
---
> SelectStmt:   select_no_parens%prec UMINUS
>   | select_with_parens%prec UMINUS
4028,4029c4041,4042
<   '(' select_no_parens ')'{ $$ = 
$2; }
<   | '(' select_with_parens ')'{ $$ = $2; }
---
>   '(' select_no_parens ')'   
> { $$ = $2; }
>   | '(' select_with_parens ')'   
> { $$ = $2; }
4031a4045
> 
4033c4047,4058
<   simple_select   { $$ = 
$1; }
---
>   simple_select  
> { $$ = $1; }
>   | WITH opt_recursive with_list simple_select
>   {
>   /* this should actually blend in subselects 
>from WITH
>* just replacing will do the WRONG THING
>*/
>   ((SelectStmt *) $4 )->with_recursive = $2;
>   ((SelectStmt *) $4 )->withClause = $3;
>   
>   $$ = $4;
>   }
> 
4039a4065,4072
> /*
>   | WITH RECURSIVE with_list select_clause sort_clause 
>opt_for_update_clause opt_select_limit
>   {
>   insertSelectOptions((SelectStmt *) $2, $3, $4,
>   nth(0, 
>$5), nth(1, $5));
>   $$ = $1;
>   }
> */
4045a4079,4087
> /*
>   | WITH RECURSIVE with_list select_clause for_update_clause 
>opt_select_limit
>   {
>   insertSelectOptions((SelectStmt *) $2, NIL, $3,
>   nth(0, 
>$4), nth(1, $4));
>   $$ = $1;
>   }
> */
> 
4051a4094,4100
>   | WITH opt_recursive with_list select_clause select_limit
>   {
>   insertSelectOptions((SelectStmt *) $4, NIL, 
>NIL,
>   nth(0, 
>$5), nth(1, $5));
>   $$ = $4;
>   }
> 
4053a4103,4141
> /*  WITH CLAUSE
>  *
>  * ANSI/ISO SQL99 p 7.13-7.14
>  *
>  */
> 
> opt_recursive:
>   RECURSIVE   { $$ = TRUE; }
>   | /*EMPTY */{ $$ = FALSE; }
>   ;
> 
> with_list:
> with_list_element { $$ = 
>makeList1($1); }
> | with_list ',' with_list_element { $$ = lappend($1, $3); }
> ;
>   
> with_list_element:
> ColId '(' name_list ')' AS select_with_parens
>   {
>   RangeSubselect *n = makeNode(RangeSubselect);
>   n->subquery = $6;
>

[HACKERS] Hirarchical queries a la Oracle. Patch.

2002-11-26 Thread Evgen Potemkin
Hi there!

Patch is posted to pgsql-patches. docs inside.
SQL 99 version will be later.

regards,

---
.evgen


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