Batch update by "update" query of cqlsh in Cassandra - cassandra

I want to do batch update for all rows, using update query. I know there is BATCH query. But, I have to list all rows..
So, I want to do something like :
UPDATE test set value=0x31 where id in ( SELECT id from test );
Is there any way doing something like the above?
The idea is the same as SQL. select all rows & and insert them into "in" part.
The reason why I want to do this is that I added a new column to the existing column family, which created null data in the new created column.
And, this cause an error for retrieving data from Cassandra.

I think the examples shown here might help: http://www.datastax.com/documentation/cql/3.1/cql/cql_reference/update_r.html?scroll=reference_ds_g4h_qzq_xj__description_unique_31
Update a column in several rows at once:
UPDATE users
SET state = 'TX'
WHERE user_uuid
IN (88b8fd18-b1ed-4e96-bf79-4280797cba80,
06a8913c-c0d6-477c-937d-6c1b69a95d43,
bc108776-7cb5-477f-917d-869c12dfffa8);

Related

Keep a field from updating in Data Factory

I'm writing a Data Flow in which I make an upsert to a Cosmos DB NoSQL database. My goal is to use a field called batch to keep track of the date of insertion of a particular document, that is, I want this field to not change over an update. I see that the AlterRow action doesn't let me choose which fields to partially upsert or not. Is there a way to accomplish this?
Agree with HimanshuSinha-msft if you select Upsert if it will update all the columns Instead select Update if with condition
equals(source1#id,source2#id)
And in sink setting select Update method as Allow update and pass partition key.
In mapping only select columns you want to update
Mapping >> Uncheck Auto mapping >> select columns you want to update
I think if you use UPSERT , then it will update all the fields , but UPDATE should allow you to do so .

Select clause editing in RedQueryBuilder

I'm looking into using RedQueryBuilder for a web-based query builder. I want my users to be able to specify what data they want to retrieve in the select clause, but the demo site
only shows selecting a single table, rendering all the columns of that table in the result. Does RedQueryBuilder support building out a more robust select clause, like specifying which specific columns to retrieve including those joined from other tables?
I'm afraid not. The project just concentrates on defining a query to return rows not what to show in those rows.
The onTableChange callback would feed you the list of tables in the expression so could go from that to a list of available columns...
Would you want/need to alter the SQL query generated or just the display of the results?
Personally I'd be interested in changing the demo into a more useful query too although the scope of that could be huge.

DB2 backup and restore db table preserving foreign key constraints

I'm currently having issue going through a test backup and restore of database table on my development machine for db2. Was never entirely successful. Although I was able to restore all data after a drop and re-create of the table, I wasn't able to reset the foreign key constraint as I got SQL error complaining that keys don't match. Here's my exact steps, I'm sure not entirely the right way to do it, but it does eventually restore the 5423 rows of data:
The process
export to /export/home/dale/comments.ixf of ixf messages /export/home/dale/msg.txt select * from .comments
Note: step 1 exports 5423 rows of data to a location
drop table .comments
import from /export/home/dale/comments.ixf of ixf create into .comments
Note: step 3 here creates the table but does not insert any data rows
load client from /export/home/dale/comments.ixf of ixf modified by identityoverride replace into .comments
Note: up until this step, I'm able to insert the 5423 rows of data in the recreated db table
alter table .comments add FOREIGN KEY (comments_id) REFERENCES .news (article_key)
Note: here alter table fails as db2 complaints that some comments_id does not match article_key
Could anyone help with my problem here? Thanks in advance
The error means that some of the rows you IMPORT into the Comments table refer to rows that do not exist in the News table.
You might not be forming the constraint correctly. The column name "comment_id" sounds like the primary key to the Comments table. You want the foreign key, which matches the primary key of the News table. It might also be called "article_key" or "article_id".
ALTER TABLE Comments
ADD FOREIGN KEY( article_key)
REFERENCES News( article_key);
If "comment_id" is really not the primary key of the "Comments" table, then the problem comes from not backing up and restoring both the News and Comments table at the same time.
You can either EXPORT and IMPORT the News table along with the Comments table, or remove the Comments that refer to missing News rows with something like this
DELETE FROM Comments
WHERE comments_id NOT IN (
SELECT article_key
FROM News
)
Before you do this, you might want to try listing the Comments which would be deleted by the above query
SELECT *
FROM Comments
WHERE comments_id NOT IN (
SELECT article_key
FROM News
)
I found a solution to my problem as well as my comments above,
user980717 resolved my first problem where I set the wrong column as the foreign key
For my 2nd issue, i.e. "SQL0668N Operation not allowed for reason code "1" on table "tablename". SQLSTATE=57016", I need to run the following command "set integrity for niwps.comments immediate checked" to ensure data satisfied all constraints defined in the table. And thanks to all who took the effort in helping me with my problems. Cheers

Copy Column Data - Azure Table Storage

So Azure Table Storage has three default member properties for its TableServiceEntity class, one of which is Timestamp. After release to Production, we now realize we need a CreatedDateTime property instead of Timestamp b/c we have no control over the Timestamp value, which acts more like a "Last Modified" value rather than "Created Date" value.
How can I copy the value in Timestamp currently over to my new property? In SQL, this seems pretty straightforward, but the cloud is a different animal. Thanks.
In Table Storage you have no schema. In a single "table" you can have 10 rows with a C# defined class of Person and 10 rows of class Dog with COMPLETELY different properties.
The reason I am saying this is because there is no schema, so the easiest thing to do would be to "re-insert" the rows as a batch with the new column/property added to the class. You can also do an UPSERT as well:
http://blogs.msdn.com/b/windowsazurestorage/archive/2011/09/15/windows-azure-tables-introducing-upsert-and-query-projection.aspx
If the column is already defined then its easy and u would just do an update, but it sounds like that new column does not exist on the previous rows entered.
If you are using a class, just add the new field for the create date time. Pull all the data down and copy the timestamp to the new field and then call update on the row. If you are already doing inserts and deletes and thigns, should be pretty straightforward.

Updating a table Access and Excel VBA

I have one table called: Transaction. This table has the following fields: (ID,ProductName,Amount,Date) placed in an excel sheet that is connected with MS Access database. ID is the only unique field. Sometimes, my user submits a transaction that has let's say 5 records. Then, they want to modify the submitted data in case if they entered incorrect amount and they want to correct it. I want to write a code in VBA that will do the update. my current query is:
Update table Transaction(ProductName,Amount) set ProductName=#Product,Amount=#Amount)
where Date=#date;
This query does not work fine because obviously it replaces all the records data with the data of the last resubmitted record because my condition is weak. My difficulty is that I can't find a good condition in the where clause that will do the update a record by record accordingly.
Please help,
You will need to use the unique id of the record, in your case the ID field to guarantee you are updating the correct record.
Something like the following:
Update table Transaction(ProductName,Amount) set ProductName=#Product,Amount=#Amount) where ID = "id of record you want to update"
Enjoy!

Resources