Search code examples
cyphermemgraphdbopencypher

Can I rename a property that already exist and that has values in it?


Is there a clause in Cypher that would allow me to rename property o.operating_system into o.os? I already have values assigned to a property.


Solution

  • In general, with Cypher/openCypher, you can do this by copying the old property and then removing it. As a concrete example, using the air-routes data set (tested using Amazon Neptune but it should work elsewhere). In this example we change the property called code to a new one named iata.

    MATCH (a:airport {code: 'SFO'})
    SET a.iata = a.code
    REMOVE a.code
    RETURN a
    

    And we can see the update has worked...

    {
      "results": [
        {
          "a": {
            "~id": "23",
            "~entityType": "node",
            "~labels": [
              "airport"
            ],
            "~properties": {
              "desc": "San Francisco International Airport",
              "lon": -122.375,
              "runways": 4,
              "type": "airport",
              "country": "US",
              "region": "US-CA",
              "lat": 37.6189994812012,
              "iata": "SFO",
              "elev": 13,
              "city": "San Francisco",
              "icao": "KSFO",
              "longest": 11870
            }
          }
        }
      ]
    }