[ 
https://issues.apache.org/jira/browse/CASSANDRA-7654?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14081511#comment-14081511
 ] 

Jack Krupansky commented on CASSANDRA-7654:
-------------------------------------------

This appears to be the duplicate - CASSANDRA-5959 - "CQL3 support for 
multi-column insert in a single operation (Batch Insert / Batch Mutate)", which 
was in turn resolved as a duplicate of CASSANDRA-4693 - "CQL Protocol should 
allow multiple PreparedStatements to be atomically executed", which is for the 
feature that [~tjake] referenced.

It used a slightly different syntax, factoring out the partition key:

{code}
insert into results (row_id, (index,value)) values 
    ((0,text0), (1,text1), (2,text2), ..., (N,textN));
{code}

Which highlights the fact that the example in this issue did not even have the 
partition key specified in either the primary key or the insert column list.

For convenient (future) reference, the batch prepared statement replaces:

{code}
PreparedStatement ps = session.prepare(
   "BEGIN BATCH" +
   "   INSERT INTO messages (user_id, msg_id, title, body) VALUES (?, ?, ?, 
?);" +
   "   INSERT INTO messages (user_id, msg_id, title, body) VALUES (?, ?, ?, 
?);" +
   "   INSERT INTO messages (user_id, msg_id, title, body) VALUES (?, ?, ?, 
?);" +
   "APPLY BATCH"
);
session.execute(ps.bind(uid, mid1, title1, body1, uid, mid2, title2, body2, 
uid, mid3, title3, body3));
{code}

with
{code}
PreparedStatement ps = session.prepare("INSERT INTO messages (user_id, msg_id, 
title, body) VALUES (?, ?, ?, ?)");
BatchStatement batch = new BatchStatement();
batch.add(ps.bind(uid, mid1, title1, body1));
batch.add(ps.bind(uid, mid2, title2, body2));
batch.add(ps.bind(uid, mid3, title3, body3));
session.execute(batch);
{code}

Granted, that doesn't help with cqlsh. It also doesn't help with DevCenter 
either, right?


> CQL INSERT improvement
> ----------------------
>
>                 Key: CASSANDRA-7654
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-7654
>             Project: Cassandra
>          Issue Type: Improvement
>            Reporter: Robert Stupp
>            Priority: Minor
>
> It would be nice to be able to add multiple rows using a single {{INSERT}}.
> Restricted to the same partition.
> For example:
> Current behaviour:
> {noformat}
> INSERT INTO comp_key (key, num_val)
>   VALUES ('foo', 1, 41);
> INSERT INTO comp_key (key, num_val)
>   VALUES ('foo', 2, 42);
> {noformat}
> Wanted behaviour:
> {noformat}
> INSERT INTO comp_key (key, num_val)
>   VALUES
>     ('foo', 1, 41),
>     ('foo', 2, 42),
>     ('foo', 3, 42),
>     ('foo', 4, 42);
> {noformat}
> Assumed table def:
> {noformat}
> CREATE TABLE comp_key (
>   key     TEXT,
>   clust   INT,
>   num_val DECIMAL,
>   PRIMARY KEY ( key, clust )
> );
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to