nyef's postmodern gripes
Sabra Crolleton
sabra.crolleton at gmail.com
Sat Jul 20 23:52:54 UTC 2013
Is there a better way to write "common table expressions " (with and with
recursive) than:
(def-sql-op :with (&rest args)
(let ((x (butlast args)) (y (last args)))
`("WITH " ,@(sql-expand-list x) ,@(sql-expand (car y)))))
(def-sql-op :with-recursive (&rest args)
(let ((x (butlast args)) (y (last args)))
`("WITH RECURSIVE " ,@(sql-expand-list x) ,@(sql-expand (car y)))))
They work for me, but I have the feeling there is a better way to do it.
Actual use would be something like the following (using the example from
the postgresql website):
(defun test2 ()
(query (:with-recursive
(:as 'regional-sales
(:select 'region (:as (:sum 'amount) 'total-sales)
:from 'orders
:group-by 'region))
(:as 'top-regions
(:select 'region
:from 'regional-sales
:where (:> 'total-sales
(:select (:/ (:sum
'total-sales) 10)
:from 'regional-sales))))
(:select 'region 'product (:as (:sum 'quantity) 'product-units)
(:as (:sum 'amount) 'product-sales)
:from 'orders
:where (:in 'region (:select 'region :from
'top-regions))
:group-by 'region 'product))))
Sabra
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/postmodern-devel/attachments/20130720/045f9b4b/attachment.html>
More information about the postmodern-devel
mailing list