Re: [racket-users] Store value with unsupported type in Postgres?

2016-01-19 Thread Ryan Culpepper

On 01/17/2016 06:35 PM, Alexis King wrote:

The DB docs for SQL type conversions[1] note that not all Postgres types
are supported by Racket, and it recommends using a cast to work around
this. It even uses the inet type as an example right at the start of the
page. However, I want to store an inet value in my database, not query
an inet value out, and I can’t figure out what set of casts I need for
the right coercion to take place.

My query looks like this:

   (query-exec conn "INSERT INTO some_table (ip) VALUES ($1)" client-ip)

Attempting to execute that query gives me the following error:

   query-exec: unsupported type
 type: inet
 typeid: 869

Is there any way to annotate this so that I can insert into that table?


Try something like

  INSERT INTO some_table (ip) VALUES ($1::text::inet)

or the corresponding CAST syntax. The first cast, ::text, determines the 
type of the parameter. The second, ::inet, converts the text to the inet 
type.


Ryan

--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Store value with unsupported type in Postgres?

2016-01-17 Thread Jon Zeppieri
How about: (query-exec conn (format "INSERT INTO some_table (ip) VALUES
(inet '~a')" client-ip))

On Sun, Jan 17, 2016 at 6:35 PM, Alexis King  wrote:

> The DB docs for SQL type conversions[1] note that not all Postgres types
> are supported by Racket, and it recommends using a cast to work around
> this. It even uses the inet type as an example right at the start of the
> page. However, I want to store an inet value in my database, not query
> an inet value out, and I can’t figure out what set of casts I need for
> the right coercion to take place.
>
> My query looks like this:
>
>   (query-exec conn "INSERT INTO some_table (ip) VALUES ($1)" client-ip)
>
> Attempting to execute that query gives me the following error:
>
>   query-exec: unsupported type
> type: inet
> typeid: 869
>
> Is there any way to annotate this so that I can insert into that table?
>
> [1]: http://docs.racket-lang.org/db/sql-types.html
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Store value with unsupported type in Postgres?

2016-01-17 Thread Marc Burns

You can cast first to a supported type:

(query-exec conn "INSERT INTO some_table (ip) VALUES (inet ($1 ::text))" 
client-ip)


On 2016-01-17 7:35 PM, Alexis King wrote:

I would like to avoid interpolating into a query if at all possible,
given that this string is not something I control. I could be very
careful about validating or sanitizing it, but this is a pretty textbook
use case for parameterized queries.


On Jan 17, 2016, at 16:19, Jon Zeppieri  wrote:

How about: (query-exec conn (format "INSERT INTO some_table (ip) VALUES (inet 
'~a')" client-ip))


--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Store value with unsupported type in Postgres?

2016-01-17 Thread Alexis King
The DB docs for SQL type conversions[1] note that not all Postgres types
are supported by Racket, and it recommends using a cast to work around
this. It even uses the inet type as an example right at the start of the
page. However, I want to store an inet value in my database, not query
an inet value out, and I can’t figure out what set of casts I need for
the right coercion to take place.

My query looks like this:

  (query-exec conn "INSERT INTO some_table (ip) VALUES ($1)" client-ip)

Attempting to execute that query gives me the following error:

  query-exec: unsupported type
type: inet
typeid: 869

Is there any way to annotate this so that I can insert into that table?

[1]: http://docs.racket-lang.org/db/sql-types.html

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Store value with unsupported type in Postgres?

2016-01-17 Thread Jon Zeppieri
Ah, that is a better idea. 

> On Jan 17, 2016, at 7:39 PM, Marc Burns  wrote:
> 
> You can cast first to a supported type:
> 
> (query-exec conn "INSERT INTO some_table (ip) VALUES (inet ($1 ::text))" 
> client-ip)
> 
>> On 2016-01-17 7:35 PM, Alexis King wrote:
>> I would like to avoid interpolating into a query if at all possible,
>> given that this string is not something I control. I could be very
>> careful about validating or sanitizing it, but this is a pretty textbook
>> use case for parameterized queries.
>> 
>>> On Jan 17, 2016, at 16:19, Jon Zeppieri  wrote:
>>> 
>>> How about: (query-exec conn (format "INSERT INTO some_table (ip) VALUES 
>>> (inet '~a')" client-ip))
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Store value with unsupported type in Postgres?

2016-01-17 Thread Jon Zeppieri
I sympathize, but using a prepared statement parameter requires support for the 
type of the parameter. If the library doesn't support it, you'll need to use 
strings (and escape them appropriately, though it looks like the library 
doesn't provide a string-escaping function), or else patch the library to 
provide support.

> On Jan 17, 2016, at 7:35 PM, Alexis King  wrote:
> 
> I would like to avoid interpolating into a query if at all possible,
> given that this string is not something I control. I could be very
> careful about validating or sanitizing it, but this is a pretty textbook
> use case for parameterized queries.
> 
>> On Jan 17, 2016, at 16:19, Jon Zeppieri  wrote:
>> 
>> How about: (query-exec conn (format "INSERT INTO some_table (ip) VALUES 
>> (inet '~a')" client-ip))
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Store value with unsupported type in Postgres?

2016-01-17 Thread Alexis King
Perfect, that works great, thank you! It looks like the precedence works
out such that I could do $1::text::inet and have it work properly, which
is clean enough for my needs.

> On Jan 17, 2016, at 16:39, Marc Burns  wrote:
> 
> You can cast first to a supported type:
> 
> (query-exec conn "INSERT INTO some_table (ip) VALUES (inet ($1 ::text))" 
> client-ip)

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Store value with unsupported type in Postgres?

2016-01-17 Thread Alexis King
I would like to avoid interpolating into a query if at all possible,
given that this string is not something I control. I could be very
careful about validating or sanitizing it, but this is a pretty textbook
use case for parameterized queries.

> On Jan 17, 2016, at 16:19, Jon Zeppieri  wrote:
> 
> How about: (query-exec conn (format "INSERT INTO some_table (ip) VALUES (inet 
> '~a')" client-ip))

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.