Re: WITH clause

From: Christopher Browne <cbbrowne(at)acm(dot)org>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: WITH clause
Date: 2003-12-13 05:18:27
Message-ID: m3y8thuwgs.fsf@wolfe.cbbrowne.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

david(at)fetter(dot)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-home homepath))

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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dennis Bjorklund 2003-12-13 07:08:32 Re: WITH clause
Previous Message Kurt Roeckx 2003-12-12 23:42:58 Walker/mutator prototype.