Re: WITH clause - Mailing list pgsql-hackers

From Christopher Browne
Subject Re: WITH clause
Date
Msg-id m3y8thuwgs.fsf@wolfe.cbbrowne.com
Whole thread Raw
In response to WITH clause  (David Fetter <david@fetter.org>)
Responses Re: WITH clause  (Dennis Bjorklund <db@zigo.dhs.org>)
List pgsql-hackers
david@fetter.org (David Fetter) wrote:
> I'm looking to the SQL WITH clause as a way to get better regex
> support in PostgreSQL.  I've been chatting a little bit about this,
> and here's an idea for a behavior.  Implementation details TBD.
>
> WITH res = match (x.foo, '([0-9]+)x([0-9]+)')
> SELECT *
> FROM x
> WHERE y = res[2]
> OR    y = res[3];

So you're proposing what amounts to the LET function in Lisp:
 (let* ((homepath (user-homedir-pathname))        (maildir (make-pathname :directory (append
                (pathname-directory                                              homepath)
            '("Mail"))))        (mailhome (merge-pathnames maildir homepath)))   (do-something-with-mail mailhome)
(do-something-with-homehomepath))
 

Or the ML let structure...

let a = 1 and b = 2 in a + b;;
- : int = 3

I think this could be a "simply smashing" idea, allowing values to get
declared once, up front, offering the further potential for them to be
reused.

Unfortunately, this doesn't seem to fit with the way WITH is defined
in SQL.

And while the LISP presentation may have "way too many parentheses,"
the ML syntax, being pretty much orthogonal to what SQL currently
offers, strikes me as being preferable.
-- 
select 'cbbrowne' || '@' || 'ntlug.org';
http://www.ntlug.org/~cbbrowne/unix.html
:FATAL ERROR -- ILLEGAL ERROR


pgsql-hackers by date:

Previous
From: Kurt Roeckx
Date:
Subject: Walker/mutator prototype.
Next
From: Dennis Bjorklund
Date:
Subject: Re: WITH clause