Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Where Union of Labels #1714

Open
jtomek opened this issue Mar 27, 2024 · 4 comments
Open

Where Union of Labels #1714

jtomek opened this issue Mar 27, 2024 · 4 comments
Labels
question Further information is requested

Comments

@jtomek
Copy link

jtomek commented Mar 27, 2024

Hi, how do I run this?

SELECT * FROM cypher('playground', $$
MATCH (n:Movie|Person)
RETURN n
$$) AS (v agtype)

I get

Query 1 ERROR at Line 31: : ERROR:  syntax error at or near "|"
LINE 2: MATCH (n:Movie|Person)
                      ^

Is this the only way to get what I want?

SELECT * FROM cypher('playground', $$
MATCH (n)
WHERE label(n) = 'Movie' or label(n) = 'Person'
RETURN n
$$) AS (v agtype)
@jtomek jtomek added the question Further information is requested label Mar 27, 2024
@rafsun42
Copy link
Member

@jtomek There is a PR (#1452) for this feature. It is based on PG15.

@diangamichael
Copy link

It seems you're trying to execute Cypher queries within a PostgreSQL environment using the cypher function. The error you're encountering is due to the incorrect usage of the '|' symbol in the label definition within your MATCH clause. In Cypher, '|' is not used to denote multiple labels for a node. Instead, you should use the IN keyword.

Here's the corrected version of your first query:

sql
Copy code
SELECT * FROM cypher('playground', $$
MATCH (n)
WHERE n:Movie OR n:Person
RETURN n
$$) AS (v agtype);
This query will match nodes that have either the label 'Movie' or 'Person'.

Alternatively, you can use your second query as you provided:

sql
Copy code
SELECT * FROM cypher('playground', $$
MATCH (n)
WHERE label(n) = 'Movie' OR label(n) = 'Person'
RETURN n
$$) AS (v agtype);

Both queries should achieve the same result, with the second one explicitly checking the labels of nodes. Choose whichever you find more readable or preferable for your use case.

@rafsun42
Copy link
Member

rafsun42 commented Apr 3, 2024

@diangamichael

In Cypher, '|' is not used to denote multiple labels for a node.

This is not correct. According to the openCypher specification, the pipe operator '|' is a valid way to define union of multiple labels.

Copy link

This issue is stale because it has been open 45 days with no activity. Remove "Abondoned" label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale Stale issues/PRs label May 19, 2024
@MuhammadTahaNaveed MuhammadTahaNaveed removed the Stale Stale issues/PRs label May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants