Hi,
What would be the best representation of the point type?
So far, I have been using following for query:
(:[] 'point-column 0) (:[] 'point-column 1)
and this for update:
'point-column (:type (concatenate 'string (write-to-string x-coordinate) "," (write-to-string y-coordinate)) point)
It works, but seems a bit of a kludge.
And how about more complex data types that use points like these http://www.postgresql.org/docs/8.4/static/datatype-geometric.html ?
Hi Slobodan,
To make this kind of thing less awkward, your best bet is to define a reader and a writer for the type. You can find the details in the reference guide [1], but in short, you'd:
- Find a Lisp type you want to use for values of this type. In this case, I think (defstruct point x y) is a good candidate. - Figure out the OID of the point type -- I usually do this by adding (print type-id) somewhere in read-field-descriptions, and then querying a row that contains the type I'm interested in. Maybe there are better ways. - Use cl-postgres:set-sql-reader to associate this OID with a reader function that converts the string (or, if you want to be super-efficient, binary) representation of the type to a lisp value. - Specialize cl-postgres:to-sql-string on the point struct type, and have it output the Postgres-compatible string representation.
Let me know if you run into trouble.
Best, Marijn
postmodern-devel@common-lisp.net