![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
10 7839 | KING | PRESIDENT | | 1981-11-17 00:00:00 | 5000 | 10 7934 | MILLER | CLERK | 7782 | 1982-01-23 00:00:00 | 1300 | 10 7369 | SMITH | CLERK | 7902 | 1980-12-17 00:00:00 | 800 | 20 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 00:00:00 | 1600 | 300 30 7521 | WARD | SALESMAN | 7698 | 1981-02-22 00:00:00 | 1250 | 500 30 7566 | JONES | MANAGER | 7839 | 1981-04-02 00:00:00 | 2975 | 20 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 00:00:00 | 1250 | 1400 30 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 00:00:00 | 2850 | 30 7788 | SCOTT | ANALYST | 7566 | 1987-04-19 00:00:00 | 3000 | 20 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 00:00:00 | 1500 | 0 30 7876 | ADAMS | CLERK | 7788 | 1987-05-23 00:00:00 | 1100 | 20 7900 | JAMES | CLERK | 7698 | 1981-12-03 00:00:00 | 950 | 30 7902 | FORD | ANALYST | 7566 | 1981-12-03 00:00:00 | 3000 | 20 (14 rows) |
#2
| |||
| |||
|
|
My question, however is the following: why is connect by needed at all? |
#3
| |||
| |||
|
|
One of my developers asked me for an equivalent to Oracle's "CONNECT BY" clause. Sure enough, there is a module called "tablefunc" which contains several overloaded incarnations of the "connectby" function. I installed some well known tables, usually used to demonstrate the "CONNECT BY" oracle clause. The relevant table is this one: |
|
My question, however is the following: why is connect by needed at all? Postgres supports ANSI standard recursive with clause which makes the following query possible: |
#4
| |||
| |||
|
|
Recursive CTE was introduced in 8.4, the connect_by module has been around much longer. |
|
But I agree: with 8.4 the connect_by module is no longer necessary, the standard CTE is a lot more portable (and even understood by Oracle 11gR2) |
#5
| ||||
| ||||
|
|
As far as I am concerned, Postgres starts with version 8.3.8 Which did not have CTE (neither normal nor recursive) |
|
In addition to that, I cannot use the keyword "level" as a column name. Because LEVEL is a reserved word in Oracle |
|
The same query that works on 11.2 fails miserably on 10.2.0.5: Connected. SQL> / with e(empno,mgr,lev) as ( * ERROR at line 1: ORA-32033: unsupported column aliasing |
|
BTW, what does "CTE" stand for? Oracle calls it "subquery factoring". |
#6
| |||
| |||
|
|
Mladen Gogala wrote on 20.05.2010 19:56: As far as I am concerned, Postgres starts with version 8.3.8 Which did not have CTE (neither normal nor recursive) |
|
Interesting, as (regular) CTEs are available since 9i IIRC |
|
BTW, what does "CTE" stand for? Oracle calls it "subquery factoring". Common Table Expression |
#7
| |||
| |||
|
|
On Thu, 20 May 2010 20:24:24 +0200, Thomas Kellerer wrote: Mladen Gogala wrote on 20.05.2010 19:56: BTW, what does "CTE" stand for? Oracle calls it "subquery factoring". Common Table Expression |
#8
| |||
| |||
|
|
Common Table Expression Could be that the term was coined in the Microsoft or Sybase world. MS SQL Server's documentation is the first place that I noticed it (which does not need to mean much). |
#9
| |||
| |||
|
| Mladen Gogala wrote on 20.05.2010 19:56: As far as I am concerned, Postgres starts with version 8.3.8 Which did not have CTE (neither normal nor recursive) In addition to that, I cannot use the keyword "level" as a column name. Because LEVEL is a reserved word in Oracle |
#10
| |||
| |||
|
| Robert Klemme wrote on 20.05.2010 20:52: Common Table Expression Could be that the term was coined in the Microsoft or Sybase world. MS SQL Server's documentation is the first place that I noticed it (which does not need to mean much). I don't know if MS created the expression before that, but the term "Common Table Expression" was one of the extensions introduced with SQL 99 |
![]() |
| Thread Tools | |
| Display Modes | |
| |