noahxzhu commented on issue #1705:
URL: https://github.com/apache/age/issues/1705#issuecomment-2041161137

   > sorry it took me this long to reply but i've got one of the slowest 
machines there is but try this: def upsert_triplet(self, subj: str, rel: str, 
obj: str) -> None: """Add triplet.""" rel = rel.replace(" ", "_").upper() 
prepared_statement = f""" MERGE (n1:`{self.node_label}` {{id: $subj}}) MERGE 
(n2:`{self.node_label}` {{id: $obj}}) MERGE (n1)-[:`{rel}`]->(n2) """ 
self._age.execCypher(prepared_statement, params={"subj": subj, "obj": obj}) 
self._age.commit() try this On Sat, Apr 6, 2024 at 4:44 PM Moturi Bostone 
***@***.***> wrote:
   > […](#)
   > let me take a look On Sat, Apr 6, 2024 at 4:35 PM Noah Zhu ***@***.***> 
wrote: > okay let me check your documents and see where the problem is do you 
mind > if i see your work > … <#m_7435983581932783017_m_8141234859897622336_> > 
On Sat, Apr 6, 2024 at 3:56 PM Noah Zhu *@*.*> wrote: have you tried > escaping 
the single quotes by doubling the single quotes like; MERGE > (n2:Entity {id: 
'It''s better for technology companies to be run by product > people'}) which 
will tell your parser to treat the single quote in your > string as part of the 
string … <#m_6476712402078747728_> On Sat, Apr 6, > 2024 at 3:10 PM Noah Zhu 
@.> wrote: Hi @M-Bostone > <https://github.com/M-Bostone> 
https://github.com/M-Bostone > <https://github.com/M-Bostone> 
https://github.com/M-Bostone > <https://github.com/M-Bostone> 
https://github.com/M-Bostone > <https://github.com/M-Bostone> For sure, I'm 
encountering some problem with > age that the behavior is little different with 
the Neo4j in some spec
 ific > case, I've already created a issue for this #1722 > <#1722> <#1722 > 
<#1722>> <#1722 > <#1722> <#1722 > <#1722>>> I'd appreciate some help. > Also I 
want to contribute to this project, but I need to learn more in > advance. — 
Reply to this email directly, view it on GitHub <#1705 > <#1705> (comment) 
<#1705 (comment) > <[#1705 
(comment)](https://github.com/apache/age/issues/1705#issuecomment-2041065431)>>>,
 or > unsubscribe > 
https://github.com/notifications/unsubscribe-auth/BFO2YCEMHQXK6WMEXQ25LTTY37Q2HAVCNFSM6AAAAABE4GDGHSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBRGA3DKNBTGE
 > 
<https://github.com/notifications/unsubscribe-auth/BFO2YCEMHQXK6WMEXQ25LTTY37Q2HAVCNFSM6AAAAABE4GDGHSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBRGA3DKNBTGE>
 > 
https://github.com/notifications/unsubscribe-auth/BFO2YCEMHQXK6WMEXQ25LTTY37Q2HAVCNFSM6AAAAABE4GDGHSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBRGA3DKNBTGE
 > 
<https://github.com/notifications/unsubscribe-auth/BFO2YCEMHQXK6WMEXQ25LTTY37Q2H
 AVCNFSM6AAAAABE4GDGHSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBRGA3DKNBTGE> 
> . You are receiving this because you were mentioned.Message ID: @.> -- men > 
I'm using the docker image which is provided on the github README.md for > some 
testing. I do can put the completed query and add like backslash, use > double 
quotes to wrap the string if the string contains single quotes or > use single 
quotes to wrap the string if the string contains double quotes. > But most of 
my time, I need to parameterize the queries that looks buggy, > especially with 
the python driver. And for now the problem from my side is > all the strings 
are from some documents, that means I need to process the > string in advance 
to put it as the parameters into the query, but that > doesn't work for now. 
There's no this kinds of problems when I use the > Neo4j. Also I can't create a 
vertex with a label contain single quotes > which works in Neo4j. — Reply to 
this email directly, view it on GitHub > <#1705 (com
 ment) > <[#1705 
(comment)](https://github.com/apache/age/issues/1705#issuecomment-2041074897)>>,
 or > unsubscribe > 
https://github.com/notifications/unsubscribe-auth/BFO2YCCQ7PVYHFUFGPDN44LY37WGLAVCNFSM6AAAAABE4GDGHSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBRGA3TIOBZG4
 > 
<https://github.com/notifications/unsubscribe-auth/BFO2YCCQ7PVYHFUFGPDN44LY37WGLAVCNFSM6AAAAABE4GDGHSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBRGA3TIOBZG4>
 > . You are receiving this because you were mentioned.Message ID: @.***> > > 
I'm working with the llamaindex, use LLM(OpenAI Model) to extract some > 
contents to triplets like [subj, rel, obj], the contents are from any pdfs > or 
txts, so that means I can't fully control what the LLM extract for me, > maybe 
the subj contains some special chars, or rel and obj as well. > > this is my 
python code > > def upsert_triplet(self, subj: str, rel: str, obj: str) -> 
None: > """Add triplet.""" > rel = rel.replace(" ", "_").upper() > 
prepared_statement = f""" > MERGE (
 n1:`{self.node_label}` {{id: %s}}) > MERGE (n2:`{self.node_label}` {{id: %s}}) 
> MERGE (n1)-[:`{rel}`]->(n2) > """ > > 
self._age.execCypher(prepared_statement, params=(subj, obj)) > 
self._age.commit() > > the extracted data could be: > > ["I", "Learned", "It's 
better for technology companies to be run by product people"] > > > or maybe 
the subj or rel also includes single quotes or double quotes > ["I", "include 
any '", "It's better for technology companies to be run by product people"] > > 
There's no problem with this kind of data in Neo4j. > > — > Reply to this email 
directly, view it on GitHub > <[#1705 
(comment)](https://github.com/apache/age/issues/1705#issuecomment-2041083817)>, 
or > unsubscribe > 
<https://github.com/notifications/unsubscribe-auth/BFO2YCAJJG2OD53YGL57NX3Y372ZLAVCNFSM6AAAAABE4GDGHSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBRGA4DGOBRG4>
 > . > You are receiving this because you were mentioned.Message ID: > 
***@***.***> >
   
   It doesn't work for me
   
   ```
   def upsert_triplet_test(subj: str, rel: str, obj: str) -> None:
       prepared_statement = f"""
           MERGE (n1:`Entity` {{id: $subj}})
           MERGE (n2:`Entity` {{id: $obj}})
           MERGE (n1)-[:`{rel.replace(" ", "_").upper()}`]->(n2)
       """
   
       ag.execCypher(prepared_statement, params={"subj": subj, "obj": obj})
       ag.commit()
   
   
   upsert_triplet_test(
       "I",
       "Learned aa",
       "s 's better for technology companies to be run by product people",
   )
   ```
   
   I got this:
   ```
   Traceback (most recent call last):
     File 
"/Users/noah/Projects/Python/age-test/.venv/lib/python3.11/site-packages/age/age.py",
 line 138, in execCypher
       cursor.execute(stmt)
   psycopg2.errors.UndefinedParameter: parameters argument is missing from 
cypher() function call
   LINE 1: SELECT * from cypher(NULL,NULL) as (v agtype);
                                           ^
   
   
   During handling of the above exception, another exception occurred:
   
   Traceback (most recent call last):
     File "/Users/noah/Projects/Python/age-test/main.py", line 142, in <module>
       upsert_triplet_test(
     File "/Users/noah/Projects/Python/age-test/main.py", line 138, in 
upsert_triplet_test
       ag.execCypher(prepared_statement, cols=[], params={"subj": subj, "obj": 
obj})
     File 
"/Users/noah/Projects/Python/age-test/.venv/lib/python3.11/site-packages/age/age.py",
 line 198, in execCypher
       return execCypher(self.connection, self.graphName, cypherStmt, 
cols=cols, params=params)
              
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File 
"/Users/noah/Projects/Python/age-test/.venv/lib/python3.11/site-packages/age/age.py",
 line 145, in execCypher
       raise SqlExecutionError("Execution ERR[" + str(cause) +"](" + stmt +")", 
cause)
   age.exceptions.SqlExecutionError: ('Execution ERR[parameters argument is 
missing from cypher() function call\nLINE 1: SELECT * from cypher(NULL,NULL) as 
(v agtype);\n                                        ^\n](SELECT * from 
cypher(NULL,NULL) as (v agtype);)', UndefinedParameter('parameters argument is 
missing from cypher() function call\nLINE 1: SELECT * from cypher(NULL,NULL) as 
(v agtype);\n                                        ^\n'))
   
   ```
   
   
   I can find the document mentioned that we can use the $ sign for the 
prepared statement, but it's for postgres procedure. From my understand of the 
python driver that it is not procedure.
   
   https://age.apache.org/age-manual/master/advanced/prepared_statements.html
   
   


-- 
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: dev-unsubscr...@age.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to