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

Postgres driver returns nothing with INSERT INTO .... RETURN @rid but RID with RETURN @rid.asString() #2038

Open
ExtReMLapin opened this issue Mar 4, 2025 · 7 comments

Comments

@ExtReMLapin
Copy link
Contributor

ExtReMLapin commented Mar 4, 2025

Hello,

I started writing more test for @robfrank 's python tests.

As per my previous opened discussion we just started exploring postgres driver usage.

Long story short here is the code :

import psycopg


with psycopg.connect(user="root", password="rootroot",
                    host='localhost',
                    port='5432',
                    dbname='ORANO_DOC',
                    sslmode='disable'
                    ) as connection:
    connection.autocommit = True
    
    with connection.cursor() as cursor:
        cursor.execute("create vertex type `TEXT_EMBEDDING` if not exists;")
        
        cursor.execute("create property TEXT_EMBEDDING.str if not exists STRING;")
        cursor.execute("create property TEXT_EMBEDDING.embedding if not exists ARRAY_OF_FLOATS;")
        
        cursor.execute('INSERT INTO `TEXT_EMBEDDING` SET str = "meow", hash = [0.1,0.2,0.3] RETURN @rid')
        results = cursor.fetchall()
        print(results)
    

        

It returns

  • [(None,)] with RETURN @rid
  • [('#213:6',)] with RETURN @rid.asString()
    Is it expected ?
@ExtReMLapin
Copy link
Contributor Author

Could be similar to

    try:
        with connection.cursor() as cursor:

            cursor.execute(f"create vertex type `TEST_TYPE_DEBUG` if not exists;")

            cursor.execute(f"create property TEST_TYPE_DEBUG.str if not exists STRING;")

            #cursor.execute(f'INSERT INTO TEST_TYPE_DEBUG (str) VALUES (%s) return str', ("mdrrrrrrrrr",))
            cursor.execute(f"{{cypher}}match (n) return count(n)")
            
            cursor.execute(f"""{{cypher}}CREATE (n:TEST_TYPE_DEBUG {{str: 'lol'}})
                RETURN n""")
            ret = cursor.fetchone()
            print(ret)

    finally:
        connection.close()
        

Returning (None, None, 'lol')

@ExtReMLapin
Copy link
Contributor Author

It happens beacause of those lines :

        Object value = switch (propertyName) {
          case "@rid" -> row.isElement() ? row.getElement().get().getIdentity() : null;
          case "@type" -> row.isElement() ? row.getElement().get().getTypeName() : null;

isElement return false but I have no idea what it means

@lvca
Copy link
Contributor

lvca commented Mar 4, 2025

If you do a query with projections, like "select firstName, lastName from client", then there is no element in the result set (the record/document/vertex/edge). Otherwise, if you do "select from client", then the whole record is used and returned, very similar to "select * from client".

@lvca
Copy link
Contributor

lvca commented Mar 4, 2025

But the first insert should return the rid, so there is an issue there.

@ExtReMLapin
Copy link
Contributor Author

For the very first post, it works with @rid.asString() because it's the property name that doesn't match with the switch/case literal @rid match.

Turning

case "@rid" -> row.isElement() ? row.getElement().get().getIdentity() : null;

Into

case "@rid" -> row.isElement() ? row.getElement().get().getIdentity() : row.getProperty(propertyName);

Fixes the issue but is it really what we should do ?

@ExtReMLapin
Copy link
Contributor Author

But the first insert should return the rid, so there is an issue there.

The cypher query also should work in my opinion as I do return n

@lvca
Copy link
Contributor

lvca commented Mar 4, 2025

case "@rid" -> row.isElement() ? row.getElement().get().getIdentity() : row.getProperty(propertyName);

Fixes the issue but is it really what we should do ?

I think this is actually correct: if not an element, it should try as a property. 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants