You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to handle the param if there're single quotes in it? #1722
Describe the bug
An error is observed when a property parameter includes a single quote.
How are you accessing AGE (Command line, driver, etc.)?
I'm using the apache-age-python package in a python project.
What data setup do we need to do?
defupsert_triplet_test(subj: str, rel: str, obj: str) ->None:
prepared_statement=f""" MERGE (n1:`Entity` {{id: %s}}) MERGE (n2:`Entity` {{id: %s}}) MERGE (n1)-[:`{rel.replace(" ", "_").upper()}`]->(n2) """ag.execCypher(
prepared_statement,
params=(
subj,
obj,
),
)
ag.commit()
upsert_triplet_test(
"I", "Learned", "It's better for technology companies to be run by product people"
)
This is the error
cursor.execute(stmt)
psycopg2.errors.SyntaxError: syntax error at or near "'s better for technology companies to be run by product people'"
What is the necessary configuration info needed?
nothing
What is the command that caused the error?
SELECT*fromag_catalog.cypher('graph_store', $$
MERGE (n1:`Entity` {id: 'I'})
MERGE (n2:`Entity` {id: 'It's better for technology companies to be run by product people'}) MERGE (n1)-[:`Learned`]->(n2)$$) as (a ag_catalog.agtype);
Not sure how to handle this case
ERROR: syntax error at or near "s"
LINE 3: MERGE (n2:`Entity` {id: 'It's better for technology com...
Expected behavior
This merge operation should be succeed.
Environment (please complete the following information):
@noahxzhu Did you try using the backslash for the cypher query? Your example above doesn't show it.
psql-16.1-5432-pgsql=# SELECT * from ag_catalog.cypher('test', $$
MERGE (n1:`Entity` {id: 'I'})
MERGE (n2:`Entity` {id: 'It\'s better for technology companies to be run by product people'})
MERGE (n1)-[:`Learned`]->(n2)
$$) as (a ag_catalog.agtype);
a
---
(0 rows)
psql-16.1-5432-pgsql=# SELECT * FROM cypher('test', $$ MATCH (v) RETURN v $$) AS (v agtype);
v
------------------------------------------------------------------------------------------------------------------------------------
----------
{"id": 844424930131969, "label": "Entity", "properties": {"id": "I"}}::vertex
{"id": 844424930131970, "label": "Entity", "properties": {"id": "It's better for technology companies to be run by product people"}
}::vertex
(2 rows)
psql-16.1-5432-pgsql=#
SELECT*fromag_catalog.cypher('graph_store', $$
MERGE (n1:`Entity`{id:'I'})
MERGE (n2:`Entity`{id:"It's better for technology companies to be run by product people"})
MERGE (n1)-[:`Learned`]->(n2)
$$) as (aag_catalog.agtype);
SELECT*fromag_catalog.cypher('graph_store', $$
MERGE (n1:`Entity`{id:'I'})
MERGE (n2:`Entity`{id:"It's better for technology companies to be run by product people"})
MERGE (n1)-[:`Learned`]->(n2)
$$) as (aag_catalog.agtype);
This worked for me alright
@markgomer
I just copy and paste yours, it seems not work
@noahxzhu Did you try using the backslash for the cypher query? Your example above doesn't show it.
psql-16.1-5432-pgsql=# SELECT * from ag_catalog.cypher('test', $$
MERGE (n1:`Entity` {id: 'I'})
MERGE (n2:`Entity` {id: 'It\'s better for technology companies to be run by product people'})
MERGE (n1)-[:`Learned`]->(n2)
$$) as (a ag_catalog.agtype);
a
---
(0 rows)
psql-16.1-5432-pgsql=# SELECT * FROM cypher('test', $$ MATCH (v) RETURN v $$) AS (v agtype);
v
------------------------------------------------------------------------------------------------------------------------------------
----------
{"id": 844424930131969, "label": "Entity", "properties": {"id": "I"}}::vertex
{"id": 844424930131970, "label": "Entity", "properties": {"id": "It's better for technology companies to be run by product people"}
}::vertex
(2 rows)
psql-16.1-5432-pgsql=#
@jrgemignani
not work on my side, I need to investigate the reason
SELECT*fromag_catalog.cypher('graph_store', $$
MERGE (n1:`Entity`{id:'I'})
MERGE (n2:`Entity`{id:"It's better for technology companies to be run by product people"})
MERGE (n1)-[:`Learned`]->(n2)
$$) as (aag_catalog.agtype);
This worked for me alright
@markgomer I just copy and paste yours, it seems not work
Try setting the search_path:
SETsearch_pathTOag_catalog;
I'm not sure why it is not working without this, though.
SELECT*fromag_catalog.cypher('graph_store', $$
MERGE (n1:`Entity`{id:'I'})
MERGE (n2:`Entity`{id:"It's better for technology companies to be run by product people"})
MERGE (n1)-[:`Learned`]->(n2)
$$) as (aag_catalog.agtype);
This worked for me alright
@markgomer I just copy and paste yours, it seems not work
Try setting the search_path:
SETsearch_pathTOag_catalog;
I'm not sure why it is not working without this, though.
After setting the search_path, now it's working, but why?
I still have the problem with the python driver, how to handle it with a param which contains single quotes, I digged into the python code, it do set the search_path, but not works
It appears that the upsert_triplet_test function's object parameter contains a single quotation, which is causing the error. 'Technology busin be run by product people' is one of the syntactic errors that the warning particularly addresses. This is probably because the Cypher query contains a syntax mistake because the single quote in the string is being read as the end of the string.
To handle this case, you can escape the single quote within the object parameter. In Python, you can escape a single quote by using another single quote. Here's how you can modify your function call to handle the single quote in the object parameter:
upsert_triplet_test(
"I", "Learned", "It''s better for technology companies to be run by product people"
)
By replacing the single quote with two single quotes (''), you escape the single quote within the string, ensuring that it is interpreted correctly in the Cypher query.
Your modified Cypher query should look like this:
SELECT*FROMag_catalog.cypher('graph_store', $$
MERGE (n1:`Entity` {id: 'I'})
MERGE (n2:`Entity` {id: 'It''s better for technology companies to be run by product people'})
MERGE (n1)-[:`Learned`]->(n2)
$$) AS (a ag_catalog.agtype);
Hi @mannas006
I just tried, it seems this doesn't work for me
<class 'psycopg2.errors.SyntaxError'> syntax error at or near "'s better for technology companies to be run by product people'"
LINE 4: MERGE (n2:`Entity` {id: 'It''s better for technology com...
Reacted by Manas Dey and Tobi Akomolede AKA Mocuto
I'm posting to report that I'm experiencing this bug as well. I do not think that this is a question, as this bug only occurs while using the apache-age python driver. Nested quotation marks work fine when querying directly in psql. If I find a workaround I will report to this thread
Reacted by Hananami, Voon Yong Shing and Ameer2896
Activity
0xnoahzhu commentedon Apr 5, 2024
When I use Neo4j, I can create like this, the edge label can also include single quote

jrgemignani commentedon Apr 5, 2024
@noahxzhu Did you try using the backslash for the cypher query? Your example above doesn't show it.
jrgemignani commentedon Apr 5, 2024
@noahxzhu Additionally, this sounds more like a question than a bug.
markgomer commentedon Apr 5, 2024
Can you put double quotes around the string?
This worked for me alright
0xnoahzhu commentedon Apr 5, 2024
@markgomer
I just copy and paste yours, it seems not work
0xnoahzhu commentedon Apr 5, 2024
@jrgemignani

not work on my side, I need to investigate the reason
markgomer commentedon Apr 5, 2024
Try setting the search_path:
I'm not sure why it is not working without this, though.
0xnoahzhu commentedon Apr 5, 2024
After setting the search_path, now it's working, but why?
0xnoahzhu commentedon Apr 5, 2024
Another question, should this work as it in Neo4j?
0xnoahzhu commentedon Apr 5, 2024
I still have the problem with the python driver, how to handle it with a param which contains single quotes, I digged into the python code, it do set the search_path, but not works

jrgemignani commentedon Apr 5, 2024
@noahxzhu
The search path is needed to see Cypher
jrgemignani commentedon Apr 5, 2024
I'm not sure I understand what you are asking. Also, keep in mind that you will likely need to backslash all non wrapping quote characters.
1 remaining item
0xnoahzhu commentedon Apr 5, 2024
The behavior in the python driver
NOT WORK
WORK
NOT WORK
NOT WORK
markgomer commentedon Apr 5, 2024
I tested this on AGE-viewer and it seems to be working... what is the error message you're getting?
0xnoahzhu commentedon Apr 5, 2024
@markgomer Thank you for your reply

it shows label name is invalid
the same on age-viewer

markgomer commentedon Apr 5, 2024
I had the same error showing up, but I worked around it by creating labels separately:
Please check if this works for you
0xnoahzhu commentedon Apr 6, 2024
unfortunately, it doesn't work on my side.
0xnoahzhu commentedon Apr 6, 2024
I did some tests with the python driver, the behavior likes below
Case 1
GOT
Case 2
GOT
Case 3
I think we shouldn't add quotes for the params in the query template, right?
GOT
Case 4
GOT
Case 5
GOT Succeed but the data like this
Case 6
GOT
mannas006 commentedon Apr 12, 2024
It appears that the upsert_triplet_test function's object parameter contains a single quotation, which is causing the error. 'Technology busin be run by product people' is one of the syntactic errors that the warning particularly addresses. This is probably because the Cypher query contains a syntax mistake because the single quote in the string is being read as the end of the string.
To handle this case, you can escape the single quote within the object parameter. In Python, you can escape a single quote by using another single quote. Here's how you can modify your function call to handle the single quote in the object parameter:
By replacing the single quote with two single quotes (''), you escape the single quote within the string, ensuring that it is interpreted correctly in the Cypher query.
Your modified Cypher query should look like this:
0xnoahzhu commentedon Apr 12, 2024
Hi @mannas006
I just tried, it seems this doesn't work for me
mannas006 commentedon Apr 12, 2024
Hello @noahxzhu
Thank you for informing me.
github-actions commentedon Jun 12, 2024
This issue is stale because it has been open 60 days with no activity. Remove "Abondoned" label or comment or this will be closed in 14 days.
github-actions commentedon Jun 26, 2024
This issue was closed because it has been stalled for further 14 days with no activity.
Mocuto commentedon Nov 26, 2024
I'm posting to report that I'm experiencing this bug as well. I do not think that this is a question, as this bug only occurs while using the apache-age python driver. Nested quotation marks work fine when querying directly in psql. If I find a workaround I will report to this thread