Hi,
It seems the TRUNCATE¹ operation is missing, would it be possible to add it to postmodern?
[1] http://www.postgresql.org/docs/9.0/interactive/sql-truncate.html
Best regards,
Marijn Haverbeke marijnh@gmail.com writes:
It seems the TRUNCATE¹ operation is missing, would it be possible to add it to postmodern?
You could, and I'd welcome such a patch. But since it's a rather simple command, you can also just use a string to issue it.
I tries the following:
(def-sql-op :truncate (&rest args) (split-on-keywords ((tables *) (only - ?) (identity - ?) (fkey - ?)) (cons :tables args) (let ((identity-str (case identity (:restart-identity "RESTART IDENTITY ") (:continue-identity "CONTINUE IDENTITY "))) (fkey-str (case fkey (:cascade "CASCADE ") (:restrict "RESTRICT ")))) `("(TRUNCATE " ,@(when only '("ONLY ")) ,@(sql-expand-list tables) ,@(when identity identity-str) ,@(when fkey fkey-str) ")"))))
But SPLIT-ON-KEYWORDS doesn't work as I thought (doesn't seem to like several optional keywords without arguments).
Would you have a suggestion on how to fix this ?
I'm also not sure about how to have the :only keyword before the tables so that it matches the order in the SQL command.
Regards,
(def-sql-op :truncate (&rest args) (split-on-keywords ((tables *) (only - ?) (identity - ?) (fkey - ?)) (cons :tables args) (let ((identity-str (case identity (:restart-identity "RESTART IDENTITY ") (:continue-identity "CONTINUE IDENTITY ")))
Where are you expecting :restart-identity or :continue-identity to come from? An argumentless split-on-keywords arg will simply be T when given.
(fkey-str (case fkey (:cascade "CASCADE ") (:restrict "RESTRICT "))))
Same here -- you don't allow any arguments to :fkey.
Marijn Haverbeke marijnh@gmail.com writes:
(def-sql-op :truncate (&rest args) (split-on-keywords ((tables *) (only - ?) (identity - ?) (fkey - ?)) (cons :tables args) (let ((identity-str (case identity (:restart-identity "RESTART IDENTITY ") (:continue-identity "CONTINUE IDENTITY ")))
Where are you expecting :restart-identity or :continue-identity to come from? An argumentless split-on-keywords arg will simply be T when given.
(fkey-str (case fkey (:cascade "CASCADE ") (:restrict "RESTRICT "))))
Same here -- you don't allow any arguments to :fkey.
I was expecting to be able to write forms such as:
(:truncate 'foo 'bar :only :restrict) (:truncate 'foo :restart-identity :cascade) (:truncate 'foo)
Ie. without keyword arguments.
I was expecting to be able to write forms such as:
(:truncate 'foo 'bar :only :restrict) (:truncate 'foo :restart-identity :cascade) (:truncate 'foo)
Ie. without keyword arguments.
That's not how split-on-keywords works, but you can very easily do that with a destructuring-bind and a few ecase forms.
postmodern-devel@common-lisp.net