2

I have a postgre table with "id" as SERIAL(auto-increment column), "name" and "instruction" columns.

I'm trying to insert into it as:

(ql/conj! recipe-table {:id nil :name "a" :instructions "b"})

*Evaluation aborted

(ql/conj! recipe-table {:id :default :name "a" :instructions "b"})

*Evaluation aborted

(ql/conj! recipe-table {:name "a" :instructions "b"})

*Evaluation aborted

But:

(ql/conj! recipe-table {:id 1 :name "a" :instructions "b"})

works, it just inserts the 1 into id, but it doesn't do the auto-increment part.

So I have access to the table, I have rights to write into it as proven by the last conj!, I just can't write it with a default value.

om-nom-nom
  • 62,329
  • 13
  • 183
  • 228
Gabriel Tudor
  • 311
  • 2
  • 8
  • 1
    Clojureql has `(def ^{:dynamic true} *debug* false)` . Set this dynamic var to true and then try, hopefully that will help you – Ankur Feb 25 '12 at 11:49
  • I tried setting that in my repl before running the insert but it didn't output anything – Gabriel Tudor Feb 25 '12 at 12:16
  • have you triesd running the query directly in postgres? – soulcheck Feb 25 '12 at 13:31
  • insert into recipe(name, instructions) values ('a', 'b') works. it will insert the right value in id. I think there is no syntax for default values in clojureql or it's not documented somewhere – Gabriel Tudor Feb 25 '12 at 14:34
  • if that's the case, why not do a simple (ql/conj! recipe-table {:name "a" :instructions "b"}) – Joost Diepenmaat Feb 27 '12 at 08:31
  • @joost because I get *Evaluation aborted, like I mentioned in the post. I think it crashes because it tries to map the fields I pass into conj to his internal representation of the table which has :id, and it fails – Gabriel Tudor Feb 27 '12 at 11:57

1 Answers1

1

I see that you have opened a ticket on Github and I'll follow up there. I will however let you know, that the correct way to insert is simply by omitting the keys which have default values, ie:

(ql/conj! recipe-table {:name "a" :instructions "b"})

If you would be so kind as to post the SQL code which generates the exact table you're working with, I'll be happy to try and reproduce the issue and correct any mistakes I might uncover. This is a tested scenario so we're either looking at a regression which has slipped past our unit tests or an issue with your database.

Lau Jensen
  • 214
  • 1
  • 4