Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

140
Visualizações
UpdateExpression to flatten the record

I have such items in Dynamo DB:

[{
  "Id": "1",
  "Data": {
    "Value": "test"
  }
},
{
  "Id": "2",
  "Data": {}
},
{
  "Id": "3"
},
{
  "Id": "4",
  "Data": {
    "Wrong": "234"
  }
}]

And I'm trying to make it flatten, but for the Data.Value field only:

[{
  "Id": "1",
  "Value": "test"
},
{
  "Id": "2"
},
{
  "Id": "3"
},
{
  "Id": "4"
}]

My Update request looks like this:

var request = new UpdateItemRequest {
    TableName = "<table>",
    Key = new Dictionary<string, AttributeValue> {{"Id", new AttributeValue("<item-id>")}},
    UpdateExpression = "SET #a = #c.#a REMOVE #c",
    ExpressionAttributeNames = new Dictionary<string, string> {
        {"#c", "Data"},
        {"#a", "Value"}
    }
};

This works well for Id = 1 and 3. But does not work for 2 and 4. I assume because it can not do a SET. It does not throw any errors, but simply does not delete the Data attribute.

Is there a way to make it in a single call?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

you just need a condition with your expression, to check if the attribute exist or not, thats it.

    ConditionExpression ="attribute_exists (#c.#a)"
    

For more détails in Amazon doncs here.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda