Reputation: 2143
I've tried using the code below:
final Session session = connection.getSession();
final String keyspaceName = session.getLoggedKeyspace();
psInsert = session.prepare(QueryBuilder
.insertInto(keyspaceName, CampaignConstants.TABLE_NAME_SAMPLE)
.value("ID", QueryBuilder.bindMarker())
.value("NAME", QueryBuilder.bindMarker())
.value("UPDATE_TIME", QueryBuilder.now()));
The column "UPDATE_TIME" is of type "timestamp". I can't modify it to "TimeUUID" type.
I'm getting this error:
com.datastax.driver.core.exceptions.InvalidQueryException: Type error: cannot assign result of function system.now (type timeuuid) to update_time (type timestamp)
The function call QueryBuilder.now() returns a Java instance of class: com.datastax.driver.core.querybuilder.Utils$FCall.
I've searched around, but the documentation doesn't specify how to use this now() function using the driver.
Upvotes: 2
Views: 356
Reputation: 87069
in CQL you need to use following expression: toTimestamp(now())
.
For Java driver 4.x it's translated into the following: instead of QueryBuilder.now()
, you need to use QueryBuilder.toTimestamp(QueryBuilder.now()
.
For Java driver 3.x, you need to wrap QueryBuilder.now()
into the QueryBuilder.fcall, something like this: QueryBuilder.fcall("toTimestamp", QueryBuilder.now())
Upvotes: 3