2014-03-11 01:13


  • cassandra

I have a column in cassandra which is of type set. Usig gocql I want to accept that column in golang code.So while accepting what should be the datatype of the variable in which the entire set is accepted.


err = session.Query("select product_list from category where category_id=?",key).Scan(&productIdList)

Product_list is of type set.So what should be the data type of productIdList in golang?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • douchengfei3985 douchengfei3985 7年前

    It looks like gocql uses a slice or array by default for Cassandra's set type.

    If that's not what you want it does let you define one of your own using the gocql.Marshaller and gocql.Unmarshaller interfaces.

    So for example:

    type Set map[string]bool
    func (s Set) UnmarshalCQL(info TypeInfo, data []byte) error {
      /* code to unmarshal your set into a Go map. from cql results */
    func (s Set) MarshalCQL(info TypeInfo) ([]byte, error) {
      /* code to marshal your set out of a go map for cql to use */

    This does however mean that you'll have to write the set output parsing yourself.

    点赞 评论 复制链接分享