doufei2194
doufei2194
2015-09-30 14:39

如何使用gocql执行cql文件?

已采纳

If you were to interface directly with Cassandra using cqlsh you could do the following:

$ cqlsh
cqlsh:test> SOURCE '/home/me/reset_db.cql'

I've tried to do this using gocql several times but I always get an error. For example, running this:

filePath := "/home/me/reset_db.cql"
SOURCE_FILE := "SOURCE (?)"
resetErr := session.Query(SOURCE_FILE, filePath).Exec()

Produces the following error:

line 1:0 no viable alternative at input 'SOURCE' ([SOURCE]...)

So what am I doing wrong here?

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

1条回答

  • dtnbjjq51949 dtnbjjq51949 6年前

    SOURCE is a shortcut in cqlsh, not valid CQL command in general.

    You'll need to read the file contents into strings and execute them.

    点赞 评论 复制链接分享

为你推荐