adegboyegaFAU opened a new issue, #2222:
URL: https://github.com/apache/age/issues/2222
**Describe the bug**
Passing strings containing apostrophes/single quotes (') as parameters
throws an error. There is a work around to get this working, however its
unsustainable.
**How are you accessing AGE (Command line, driver, etc.)?**
- python driver (psycopg2)
**What data setup do we need to do?**
```python
import psycopg2
import age
import json
GRAPH_NAME = "test_graph"
conn = psycopg2.connect(host="localhost", port="5432", dbname="postgres",
user="postgres", password="password")
age.setUpAge(conn, GRAPH_NAME)
with conn.cursor() as cursor:
try :
cursor.execute(
"""
SELECT * from cypher(
%s,
$$ CREATE (c:testnode {node_id: %s, node_text: %s}) RETURN c
$$
) as (c agtype);
""",
(GRAPH_NAME , "test_id", "This isn't working!") )
except Exception as ex:
print(type(ex), ex)
# if exception occurs, you must rollback all transaction.
conn.rollback()
else:
conn.commit()
result = cursor.fetchall()
print(result)
```
**What is the command that caused the error?**
```python
cursor.execute(
"""
SELECT * from cypher(
%s,
$$ CREATE (c:testnode {node_id: %s, node_text: %s}) RETURN c
$$
) as (c agtype);
""",
(GRAPH_NAME , "test_id", "This isn't working!") )
```
```
ERROR: <class 'psycopg2.errors.SyntaxError'> syntax error at or near "'t
working!'"
LINE 4: ...ATE (c:testnode {node_id: 'test_id', node_text: 'This isn''t
working...
```
**Expected behavior**
The expected output should be:
```python
[({label:testnode, id:1688849860263941, properties:{node_id: test_id,
node_text: This isn't working!, }}::VERTEX,)]
```
**Environment (please complete the following information):**
- Age Version: 1.5.0
- Postgresql Version: 1.6.0
**Additional context**
Enclosing the string in single quotes rather than double quotes and escaping
the apostrophe within the string by adding another apostrophe seems to work,
although it removes the apostrophe entirely.
```python
with conn.cursor() as cursor:
try :
cursor.execute(
"""
SELECT * from cypher(
%s,
$$ CREATE (c:testnode {node_id: %s, node_text: %s}) RETURN c
$$
) as (c agtype);
""",
GRAPH_NAME , "test_id", 'This isn''t working!') )
except Exception as ex:
print(type(ex), ex)
# if exception occurs, you must rollback all transaction.
conn.rollback()
else:
conn.commit()
result = cursor.fetchall()
print(result)
```
```python
OUTPUT: [({label:testnode, id:1688849860263941, properties:{node_id:
test_id, node_text: This isnt working!, }}::VERTEX,)]
```
Notice how the output doesn't contain the apostrophe in the word: `isn't`.
This doesn't appear sustainable in an application because while its possible
to replace every occurrence of an apostrophe with two apostrophes, I'm not sure
its possible to explicitly declare a string with single quotes rather than
double quotes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]