admin管理员组

文章数量:1313347

I'm having issues with extracting any string properties from an Apache AGE graph to PostgreSQL. It seems like AGE is adding double quotes (") to each string when the node gets created and when it's returned to regular SQL, it thinks that the quotes are part of the string itself. Happens to all properties as long as the type is string.

This causes an issue down the line when I'm trying to run a JOIN statement that includes a Cypher query - the join condition isn't picking up because the string aren't the same.

I use PostgreSQL 14.15, Apache AGE 1.5.0 and psycopg2 2.9.6 to communicate with db via Python

Here's my create statement for the node:

 SELECT * 
    FROM cypher('graph', 
    $$ CREATE (n:NODE {id: "1b920981-635b-4e46-bb75-17ab6cac9716"}) $$) 
as (a agtype); 

When I try to retrieve it, the end result looks like this:


query = '''SELECT * FROM
            cypher('graph', $$
                    MATCH (b:NODE)
                    WHERE b.id = '1b920981-635b-4e46-bb75-17ab6cac9716'
                    RETURN b.id
            $$) as graph_query(id varchar)
            '''

with conn.cursor() as cursor:
    cursor.execute(query)
    print(cursor.fetchall())
    connmit()

[('"1b920981-635b-4e46-bb75-17ab6cac9716"',)]

That '"{id}"' is the issue - somehow the double quotes become part of the string. If I switch graph_query(id varchar) to graph_query(id agtype), issue persists.

本文标签: