Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

142
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda