marijnh / Postmodern

A Common Lisp PostgreSQL programming interface
http://marijnhaverbeke.nl/postmodern
Other
400 stars 90 forks source link

Possible bug: primary-key value not compiled correctly #353

Closed mmontone closed 4 months ago

mmontone commented 4 months ago

When I compile an SQL expression with :primary-key in NIL, I get an incorrect PRIMARY KEY sql output nonetheless.

DB> (s-sql:sql-compile '(:create-table my-table
                         ((id :type integer :primary-key t)
                          (non-primary :type string :primary-key nil))))
"CREATE TABLE my_table (id INTEGER NOT NULL PRIMARY KEY , non_primary TEXT NOT NULL PRIMARY KEY )"

I expect PRIMARY KEY not present for non_primary column.

I have to check with latest Postmodern yet, I'm using Quicklisp version.

mmontone commented 4 months ago

It also happens with latest Github version.

mmontone commented 4 months ago

I can prevent by not passing :primary-key , but docs mention I can pass with NIL. https://marijnhaverbeke.nl/postmodern/s-sql.html#sql-op-create-table

svantevonerichsen6906 commented 4 months ago

I think I'd expect the same, nil being the same as the option not given.

The problem seems to be in s-sql.lisp, line 2178 (in function expand-table-column), where this should probably just be checked as another case:

((null value)
 '())

This should probably be the first clause, so that we can omit and value in the others.

sabracrolleton commented 4 months ago

Is someone going to submit a pull request?

sabracrolleton commented 4 months ago

Just committed @svantevonerichsen6906 's suggestion and fixed the relevant tests. Thank you both for identifying it and the suggested fix.

mmontone commented 4 months ago

Thanks for the fix!