Closed mottalrd closed 10 years ago
You're using the wrong syntax. id IN (?)
means the same as id = ?
. You need to drop the parentheses to make it work as a bound list: id IN ?
.
Prepared statements have a metadata
property that can show you how the statement has been parsed by the server. With id IN (?)
you can see that a VARCHAR
is expected, but with id IN ?
it changes to LIST<VARCHAR>
:
statement = client.prepare('SELECT * from playlists where id IN (?) ORDER BY song_order')
statement.metadata.each do |column|
p [column.column_name, column.type]
end
vs.
statement = client.prepare('SELECT * from playlists where id IN ? ORDER BY song_order')
statement.metadata.each do |column|
p [column.column_name, column.type]
end
([:list, :varchar]
is cql-rb's representation of LIST<VARCHAR>
)
Ok! thanks
Thanks, this is very helpful.
Also, it seems like cql-rb expects the client to build Cql::UUID
objects rather than strings that are properly-formatted stringified UUID's. It looks like the encoder looks up the column metadata when performing a query and if the column is a UUID, it assumes you've passed it a UUID and invokes the value
method on it, which String
does not have.
Yes, if a column is a UUID or TIMEUUID you need to pass a real UUID to the prepared statement. UUIDs have a non-string encoding in the protocol so string representations of UUIDs don't work.
Hello,
I have this list of ids retrieved from my cluster
Now I want to execute this statement
I have tried both
and
I ended up building the query string manually in ruby. What I am doing wrong?
To reproduce I am attaching the keyspace definition, the table definition, and some sample data (all cql)