Juan Fuentes
Juan Fuentes

Reputation: 1771

Cypher query: Set nodes properties to lowercase

I have some tag nodes with a name property. After a while I started creating them with name in lowercase to avoid multiple instances of the same tag with different letters (ex: tag, Tag, etc).

I would like to update existing tags with uppercase names and set them to lowercase, is this possible with a cypher query?

Upvotes: 2

Views: 2098

Answers (1)

Mikesname
Mikesname

Reputation: 8901

Something like the following should work:

MATCH (tag:Tag)
WHERE exists(tag.name) AND tag.name =~ '.*\\p{Lu}.*'
SET tag.name = lower(tag.name)
RETURN tag.name, lower(tag.name)

If you want all tag properties to be lowercase you could simply skip the regex check, but just for completeness, this should match anything that contains an uppercase-class character (\p{Lu}).

As always, you should backup your DB before running this kind of destructive change!

Upvotes: 3

Related Questions