FSharp.AWS.DynamoDB icon indicating copy to clipboard operation
FSharp.AWS.DynamoDB copied to clipboard

defaultArg/if_not_exists for the same attribute

Open matti-avilabs opened this issue 1 year ago • 0 comments

I'm trying to figure out if there's any way to achieve the same end result as is given in the Preventing overwrites of an existing attrubute section from here:

aws dynamodb update-item \
    --table-name ProductCatalog \
    --key '{"Id":{"N":"789"}}' \
    --update-expression "SET Price = if_not_exists(Price, :p)" \
    --expression-attribute-values '{":p": {"N": "100"}}' \
    --return-values ALL_NEW

So far I haven't been successful in any of my attempts so wondering if there's something I'm missing? From digging around it seems if defaultArg would be the way to go but as far as I can tell the only way to construct a valid update expression using that is if the attribute being set and the one passed into defaultArg are not the same ones.

I've tried the following but the resulting expressions are invalid in both cases:

For optional attributes: SET p.Price (defaultArg p.Price price |> Some) For non-optional attributes: SET p.Price (defaultArg (Some p.Price) price)

matti-avilabs avatar Mar 26 '24 15:03 matti-avilabs