Azure CosmosDB replace a row with a unique key - azure

Is there an easy way to overwrite a row that contains a unique index, rather than just failing?
Or do I need to do an update and/or a delete then add.
It would be nice to have a setting when trying to add a row that would violate a unique index constraint it would replace the exist row that matches that the unique index.
My db is defined on Azure using a Core (SQL) API. Any thoughts?

Use UpsertItemAsync(). This will work.

Related

Power Apps: Item Level Permission Error: document library contains a column that enforces unique values

I am trying to make my power app have the functionality where only the user using the app can read their own items and edit their own created items.
Getting error Cannot change item-level permissions because this list or document library contains a column that enforces unique values.
Is there a way to fix this? I need some columns to be unique records to identify each unique user.
Thanks.
I'm afraid there is no solution to this unless you disable the unique value of those columns.
It seems like while submitting some column contains duplicate value. Check each unique enforced column value have unique value.

Azure Table Storage as Sink in Data Factory Row Key

I want to pass a value for the row key as a parameter just like the partition key. But the UI only gives me an option to use unique identifier or a source column. Actually I need to use this same entity somewhere else. How will I query this entity if the row key is going to be a random value?
Based on the official statement , partition key can be set custom value yet row key only could be set column name from source or GUID default value.
I think it's because of guaranteed uniqueness constraint restrictions. So, if you want to control row key value , you could add row key into your source data.
Hope it helps you.

Get list of keys where column equals some value?

If I have secondary index on column STATUS I would like to get all keys (within some range) that have STATUS='processed'. How can I do that without reading any columns? I just need the list of keys so only index should be accessed (one disk seek per node instead of 2).
Secondary indexes are not directly accessible to the user, so you'd need to run an index query against the CF you've indexed and get the keys. If you want to be guaranteed only one disk seek, you'll need to create your own index (i.e. a CF containing all "processed" keys) so you can query it directly.

Azure Table Storage: Order by

I am building a web site that has a wish list. I want to store the wish list(s) in azure table storage, but also want the user to be able to sort their wish list, when viewing it, a number of different ways - date added, date added reversed, item name etc. I also want to implement paging which I believe I can implement by making use of the continuation token.
As I understand it, "order by" isn't implemented and the order that results are returned from table storage is based on the partition key and row key. Therefore if I want to implement the paging and sorting that I describe, is the best way to implement this by storing the wish list multiple times with different partition key / row key?
In this simple case, it is likely that the wish list won't be that large and I could in fact restrict the maximum number of items that can appear in the list, then get rid of paging and sort in memory. However, I have more complex cases that I also need to implement paging and sorting for.
On today’ s hardware having 1000’s of rows to hold, in a list, in memory and sort is easily supportable. What the real issue is, how possible is it for you to access the rows in table storage using the Keys and not having to do a table scan. Duplicating rows across multiple tables could get quite cumbersome to maintain.
An alternate solution, would be to temporarily stage your rows into SQL Azure and apply an order by there. This may be effective if your result set is too large to work in memory. For best results the temporary table would need to have the necessary indexes.
Azure Storage keeps entities in lexicographical order, indexed by Partition Key as primary index and Row Key as secondary index. In general for your scenario it sounds like UserId would be a good fit for a partition key, so you have the Row Key to optimize for per each query.
If you want the user to see the wish lists latest on top, then you can use the log tail pattern where your row key will be the inverted Date Time Ticks of the DateTime when the wish list was entered by the user.
https://learn.microsoft.com/azure/storage/tables/table-storage-design-patterns#log-tail-pattern
If you want user to see their wish lists ordered by the item name you could have your item name as your row key, and so the entities will naturally sorted by azure.
When you are writing the data you may want to denormalize the data and do multiple writes with these different row key schemas. Since you will have the same partition key as user id, you can at that stage do a batch insert operation and not worry about consistency since azure table batch operations are atomic.
To differentiate the different rowkey schemas, you may want to prepend each with a const string value. Like your inverted ticks row key value for instance woul dbe something like "InvertedTicks_[InvertedDateTimeTicksOfTheWishList]" and your item names row key value would be "ItemName_[ItemNameOfTheWishList]"
Why not do all of this in .net using a List.
For this type of application I would have thought SQL Azure would have been more appropriate.
Something like this worked just fine for me:
List<TableEntityType> rawData =
(from c in ctx.CreateQuery<TableEntityType>("insysdata")
where ((c.PartitionKey == "PartitionKey") && (c.Field == fieldvalue))
select c).AsTableServiceQuery().ToList();
List<TableEntityType> sortedData = rawData.OrderBy(c => c.DateTime).ToList();

Insert rows into Access db from C# using Microsoft.Jet.OLEDB.4.0, autonumber column is set to zero

I'm using C# and Microsoft.Jet.OLEDB.4.0 provider to insert rows into an Access mdb.
Yes, I know Access sucks. It's a huge legacy app, and everything else works OK.
The table has an autonumber column. I insert the rows, but the autonumber column is set to zero.
I Googled the question and read all the articles I could find on this subject. One suggested inserting -1 for the autonumber column, but this didn't work. None of the other suggestions I could find worked.
I am using OleDbParameter's, not concatenating a big SQL text string.
I've tried the insert with and without a transaction. No difference.
How do I get this insert to work (i.e. set the autonumber column contents correctly)?
Thanks very much in advance,
Adam Leffert
In Access it is possible to INSERT an explicit value into an IDENTITY (a.k.a. Automnumber) column. If you (or your middleware) is writing the value zero to the IDENTITY column and there is no unique constraint on the IDENTITY column then that might explain it.
Just to be clear you should be using the syntax
INSERT INTO (<column list>) ...
and the column list should omit the IDENTITY column. Jet SQL will allow you to omit the entire column list but then implicitly include the IDENTITY column. Therefore you should use the INSERT INTO () syntax to explicitly omit the IDENTITY column.
In Access/Jet, you can write explicit values to the IDENTITY column, in which case the value will obviously not be auto-generated. Therefore, ensure both you and your middleware (ADO.NET etc) are not explicitly writing a zero value to the IDENTITY column.
BTW just for the IDENTITY column in the below table will auto-generate the value zero every second INSERT:
CREATE Table Test1
(
ID INTEGER IDENTITY(0, -2147483648) NOT NULL,
data_col INTEGER
);
When doing the insert, you need to be sure that you are NOT specifying a value for the AutoNumber column. Just like in SQL Server you don't insert a value for an identity column.

Resources