marijnh / Postmodern

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

case-sensitive column names? #313

Closed CGenie closed 1 year ago

CGenie commented 1 year ago

Hello,

I have a column "ownerId" in my db. How can I query that using s-sql?

I tried:

(query (:select '|ownerId| :from 'mytable))

but it doesn't help and I don't have any more ideas :)

sabracrolleton commented 1 year ago

You can try

(setf *escape-sql-names-p* :literal)

and then see if your query works. However as noted in https://marijnhaverbeke.nl/postmodern/s-sql.html#variable-escape-sql-names-p "Mixed case sensitivity is not currently well supported. Postgresql itself will downcase unquoted identifiers.".

sabracrolleton commented 1 year ago

Ok. No response on the use of *escape-sql-names-p* so I am closing this.

CGenie commented 1 year ago

Sorry, I didn't notice this and I haven't worked with postmodern for a while.

Thing is, with *escape-sql-names-p* set to :literal I now have to quote everything, otherwise I'm getting an error that MYTABLE (uppercase) doesn't exist :)

sabracrolleton commented 1 year ago

Ok. Try this. Leave s-sql:*escape-sql-names-p as :auto (the default) Add your column name to the s-sql:*postgres-reserved-words hash:

(setf (gethash "ownerId" s-sql:*postgres-reserved-words*) t)    

Change the configuration variable s-sql:*downcase-symbols* to nil

(setf s-sql:*downcase-symbols* nil)

Now try your query:

(query (:select '|ownerId| :from 'mytable))

That should get you what you want.

CGenie commented 1 year ago

OK this works, thank you!