RLe
RLe

Reputation: 486

execute .sql file in cassandra

I want to be able to execute my sql files in cassandra but not sure which command should i use to do it on command promt. I'm using windows 10 but I dont use installer for cassandra. Thanks

Upvotes: 1

Views: 3504

Answers (1)

Aaron
Aaron

Reputation: 57748

Common misconception, but the Cassandra Query Language (CQL) is not the same as SQL. You will not be able to use keywords like JOIN, OR, or GROUP BY in CQL. If you really are trying to run a file containing SQL commands, you can stop reading right now because it likely will not work.

On the other hand, if you intend to execute a file of CQL commands on your Cassandra cluster, you can do this with the -f flag on the cqlsh utility (which is located in the same bin directory as the cassandra executable).

If I have a getTop3Users.cql file that looks like this:

use stackoverflow;
SELECT firstname,city FROM users LIMIT 3;

I can run those commands on my local node, via a command prompt like this:

cqlsh -u username -p password -f getTop3Users.cql 127.0.0.1

 firstname | city
-----------+-----------------
      Rick |          Albany
     Brian | Sheboygan Falls
     Aaron |     Maple Grove

(3 rows)

Upvotes: 3

Related Questions