From asf at boinkor.net Thu Apr 9 12:07:22 2009 From: asf at boinkor.net (Andreas Fuchs) Date: Thu, 9 Apr 2009 14:07:22 +0200 Subject: [postmodern-devel] s-sql: Better join keyword recognition Message-ID: Hi there, I'd really like to use the NATURAL JOIN facility in postgresql as outlined in http://www.postgresql.org/docs/8.3/interactive/queries-table-expressions.html, so my first instinct was to patch s-sql (-: This patch also fixes the syntax emitted for :cross-join (it really doesn't require an :ON) and adds a :USING keyword to specify the same-named columns to use for joining. The result can be used like so: (:select 'x 'y :from 'foo :cross-join 'bar) (:select 'x 'y :from 'foo :natural-left-join 'bar :where (:= 'a 2)) (:select 'x 'y :from 'foo :natural-inner-join 'bar :where (:= 'a 1)) (:select 'x 'y :from 'foo :outer-join 'bar :using ('a 'b 'c)) ;;; which is mostly equivalent to: (:select 'x 'y :from 'foo :inner-join 'bar :on (:and (:= 'foo.a 'bar.a) (:= 'foo.b 'bar.b) (:= 'foo.c 'bar.c))) I hope you find the attached patch useful, and will consider committing it. Cheers, -- Andreas Fuchs, (http://|im:asf@|mailto:asf@)boinkor.net, antifuchs -------------- next part -------------- A non-text attachment was scrubbed... Name: s-sql-join-keyword-improvements.patch Type: application/octet-stream Size: 5109 bytes Desc: not available URL: From marijnh at gmail.com Thu Apr 9 13:35:27 2009 From: marijnh at gmail.com (Marijn Haverbeke) Date: Thu, 9 Apr 2009 15:35:27 +0200 Subject: [postmodern-devel] s-sql: Better join keyword recognition In-Reply-To: References: Message-ID: Hey Andreas, I like the idea, but can't really live with the code you submitted. I've implemented something similar, except without the funky hacks, and with :natural occurring as a separate keyword, so you'd get... > (:select 'x 'y :from 'foo :natural :left-join 'bar :where (:= 'a 2)) It's in the repository. Could you see if it works for you? Cheers, Marijn From asf at boinkor.net Thu Apr 9 20:41:25 2009 From: asf at boinkor.net (Andreas Fuchs) Date: Thu, 9 Apr 2009 22:41:25 +0200 Subject: [postmodern-devel] s-sql: Better join keyword recognition In-Reply-To: References: Message-ID: 2009/4/9 Marijn Haverbeke : > Hey Andreas, Hi Marijn, > I like the idea, but can't really live with the code you submitted. > I've implemented something similar, except without the funky hacks, > and with :natural occurring as a separate keyword, so you'd get... > >> (:select 'x 'y :from 'foo :natural :left-join 'bar :where (:= 'a 2)) > > It's in the repository. Could you see if it works for you? Works like a charm. Looking at it again, what I submitted is pretty awful code; what you committed is way better. Thanks a lot, -- Andreas Fuchs, (http://|im:asf@|mailto:asf@)boinkor.net, antifuchs