Re: WITH RECURSIVE ... simplified syntax?

From: "Dickson S(dot) Guedes" <guediz(at)gmail(dot)com>
To: josh(at)agliodbs(dot)com
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: WITH RECURSIVE ... simplified syntax?
Date: 2008-10-09 02:58:38
Message-ID: 48ED735E.1060008@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Josh Berkus escreveu:
> All,
>
> I was discussing WITH RECURSIVE the other day, and realized that one thing
> which we're not getting with this patch is a simplest-case simple syntax
> which 75% of users are looking for. You know, the ones with simple
> proximity trees who just want to find all children of one parent.
>
> Would it be a worth it for us to implement a non-standard simple syntax
> sugar on top of WITH RECURSIVE? Or, at least, something like
> CONNECT_BY()

Yes Josh,

I was discussing WITH RECURSIVE with some students that I'm teaching and
they ask me exactly this:

"Why not use a syntax like...

SELECT level, lpad(' ', level*4) || last_name as last_name
FROM employee
START WITH employee_id = 10
CONNECT BY PRIOR employee_id = manager_id;

... that is rewrite (or aliased) in:

WITH RECURSIVE employee_rec(level, employee_id, last_name) AS
(SELECT 1, employee_id, last_name)
FROM employee
WHERE employee_id = 10
UNION ALL
SELECT employee_rec.level + 1, emp.employee_id, emp.last_name
FROM employee as emp, employee_rec
WHERE employee_rec.employee_id = emp.manager_id)
SELECT level, lpad(' ', level*4) || last_name FROM employee_rec;" ?

In my opnion, it will be more simple to understand too.

--

[]s
Dickson S. Guedes
Administrador de Banco de Dados
Projeto Colmeia - Florianópolis, SC
(48) 3322-1185, ramal: 26

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2008-10-09 02:59:03 Re: [WIP] plpgsql is not translate-aware
Previous Message ITAGAKI Takahiro 2008-10-09 02:41:19 Re: autovacuum and reloptions