I want to Update TimeStamp property in my DB node

Hi there. I'm facing a bit issue in updating timestamp while keeping previous values. Let me try to explain it by some queries that I have tried
MERGE (E1:Person)
SET E1.timestamp += timestamp()
According to refcard aforementioned query will update value while keeping previous value of individual property in a node. But when I ran mentioned query it return this error "Neo.ClientError.Statement.SyntaxError: Invalid input '+': expected whitespace, comment, '(', '.' or '=' (line 2, column 20 (offset: 37))
" SET E1.timestamp += timestamp()"
Actually I'm working on profiling data and whenever any entity is detected in system it will log it's location, timestamp. I have also tried
MATCH (person), (Location) WHERE person.name = "Siraj" AND Location.name = "Karachi"
CREATE (person)-[: LOCATED_AT]->(Location)
MERGE (E:Person)
SET E.timestamp += timestamp()
RETURN person,Location
it's again throwing same error that I mentioned above. And if I'm just using same query with just "=" it overwrites the previous value
Any suggestion? #projects-collaboration # NeedHelpCypher

I tried this query MERGE (loc:Location)
SET loc.timestamp = timestamp() + [timestamp()]
but issue is first it overwrites previous value then add new value :frowning:

The += operator is meant for property updates using a map structure (such as when you have a map of properties to apply/update, but you don't want to wipe out all the other properties that aren't getting replaced), not for updating an individual property.

What you seem to be looking for is setting your property to a list structure, and adding a new value onto the list. You can do that with:

SET E1.timestamp = [E1.timestamp] + timestamp()

Though keep in mind this complicates executing this in the future, as once the timestamp property is a list, this will be attempting to nest it within another list, which isn't allowed on properties and you'll get an error.

I'd encourage you to either transform all of your timestamp properties to lists at the start (allowing you to simply use the + operator on the original property to add to the list, so you won't be forced to use different syntax depending on if the property is an integer or a list) or refactor your model so you have timestamp nodes connected to each :Person node.

Also make sure you use labels in your queries, your second query will have poor performance since no labels are specified (indexes can't be used if you have them set up). Also your MERGE (E:Person) is incorrect, as this will match to all :Persons in your graph (it has nothing to do with your prior MATCH and CREATE) and attempt to set all of their timestamps (erroring out of course because of syntax).

1 Like

Thanks for your detailed response :blush: Actually timestamp is connected to person node but as my scenario is to maintain profile of person and track his/her location. I have no hassle with getting data. I'm using Neo4j for better graphical visualization of data. And as planning I would have a CSV/ Big Data stream from which I would make graph database and so on. And person/ human are dynamic movement wise so location and timestamp are two things which would repeat again and again. I have tackled location updates on dummy data but I'm facing issues with the timestamp value. Any other suggestions for my mentioned scenario. Gracias :slight_smile:

Hi andrew I wanna ask you 1 things that is when i'm trying to save timestamp in the mentioned way it's updating timestamp of each graph node. Any thought why it's happening?

Finally resolved it by the help of this great article on https://medium.com/neo4j/graph-versioning-episode-one-time-based-564ac897c59e :):sunglasses::heart_eyes: