Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

chandrasekar.b03_190734 avatar image
chandrasekar.b03_190734 asked ·

How are UDT values inserted using the Python driver?

I need to insert values of type SET and uuid into my C* table. I'm using python in this case with driver installed. (I prefer getting input from users)

userid = uuid.uuid1() //primary key value

tag= set()

tag.add(input(' ')) //two values are added

tag.add(input(''))

Let me know how to insert :)

python driver
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

bettina.swynnerton avatar image
bettina.swynnerton answered ·

Hi @chandrasekar.b03_190734,

there are a couple of ways to insert UDTs into Cassandra with the Python driver.

Have a look at the documentation here:

https://docs.datastax.com/en/developer/python-driver/3.24/user_defined_types/

You can tell the Python driver to return columns of a specific UDT as instances of a class or a dict by registering them with your Cluster instance through Cluster.register_user_type()

This is the approach that is used in the week4 example code:

Or, if you are using prepared statements, you can omit registering the type, this is the approach used in the week3 example code.

The driver docs have additional simpler examples.

I hope this helps.


Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.