[racket] Is it possible to write uuids to postgres with the racket db?

From: Ryan Culpepper (ryanc at ccs.neu.edu)
Date: Mon Jul 21 15:46:13 EDT 2014

On 07/20/2014 09:07 PM, joshua at anwu.org wrote:
>
> Hey all,
>
> Anyone know how to get Racket's db to write to a uuid column in
> Postgres?  I keep getting "unsupported type".  The documentation
> suggests casting as a workaround, but the example is a select - I
> doubt that will work as well for an insert...?

It works for insert too, but you have to specify both the input type and 
field type. I haven't tried uuids specifically, but here's an example 
with inet fields.

(query-exec c
   "create temporary table t (ip inet)")
(query-exec c
   "insert into t (ip) values ($1::text::inet)"
   ;; The following works too:
   ;; "insert into t (ip) values (cast($1::text as inet))"
   "127.0.0.1")
(query-list c "select ip::text from t")
;; => '("127.0.0.1/32")

The first cast (text) gets interpreted as the parameter type, and the 
second cast (inet) gets interpreted as a conversion.

Ryan


Posted on the users mailing list.