sexp query language

Daniel Barlow <[email protected]> Mon, 27 Sep 2004 23:59:51 +0100
Newsgroups gmane.lisp.clump
Message-ID <[email protected]>
--===============0512047150==
Content-Type: multipart/signed; boundary="=-=-=";
	micalg=pgp-sha1; protocol="application/pgp-signature"

--=-=-=


Did you know that

SELECT foo,bar 
   from table1 
   join (select * from table2 where some_criterion limit 10) table2
   on table1.table2id=table2.id

is (according to the postgres manual, at least) valid SQL?  After
finding a need for such a query on Saturday, and that my existing
fairly ad-hoc sexpr-to-sql translator wouldn't cope with having entire
'select' statements where it was expecting table names, I set out to
design something that would.  And that doesn't use custom reader
macros, which I dislike (they confuse my editor, and there always
seems to be something else that wants to redefine them incompatibly)

By working through the Postgres documentation and constructing nested
forms based on the order it claimed pgsql does things in, I arrived at
a syntax which is probably not completely unlike the parse tree that a
SQL processor would generate.  Thus

(select (foo bar) 
        (join table1 
              (alias (limit (select (*) (where table2 some-criterion))
                            :end 10) table2)
              :on (= table1.table2id table2.id)))

will translate to the sql form above.  The immediate objective is to
make it much easier to programmatically compose queries.

* I think the . notation for qualifying a column name with its table
  is a wart, inasmuch as it makes it more difficult for Lisp code to
  establish whether table1.id is id or not.

* The use of symbol names is possibly contentious: we face "the
  package problem" encounterd by all apps that build big trees of
  symbols: do we (a) export all the valid operators from the SEXQL
  package and expect callers to :USE it, (b) ask callers to use
  keywords, or (c) do as LOOP does and compare symbol names instead of
  symbol identity?  A quick poll of #lisp irc suggested that (c) was
  the best idea and accordingly it's the one I've adopted.

I have provisionally called this beast SEXQL, because the name SQL has
been taken already and SEXPQL is awkward to pronounce.  The
implementation is still work-in-progress and I haven't been through
the whole sql language thoroughly; I've just added the tokens I have a
need for as I go along.

You can see it, such as it is, at
http://cvs.telent.net/cgi-bin/viewcvs.cgi/sexql/sexql.lisp?view=markup

Feedback welcome



-dan

-- 
"please make sure that the person is your friend before you confirm"

--=-=-=
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQBBWJtsHDK5ZnWQiRMRArYrAJ46HZIA6IYsO1APXkkYcTSUAeKFKgCgxSBQ
p6iZVd5ehdhRhsTTfhR3Ri4=
=Qjii
-----END PGP SIGNATURE-----
--=-=-=--


--===============0512047150==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Clump mailing list
[email protected]
http://manly.caddr.com/mailman/listinfo/clump

--===============0512047150==--