kuzu icon indicating copy to clipboard operation
kuzu copied to clipboard

RuntimeError: Binder exception: Variable __existence already exists.

Open sapalli2989 opened this issue 9 months ago • 0 comments

Hi, above error can be reproduced by following snippet:

import kuzu
from uuid import uuid4
import tempfile

with tempfile.TemporaryDirectory() as dbpath:
    conn = kuzu.Connection(kuzu.Database(dbpath))
    conn.execute(
        """
        CREATE NODE TABLE T (id UUID, PRIMARY KEY(id));
        CREATE NODE TABLE U (id UUID, name STRING, PRIMARY KEY(id));
        CREATE REL TABLE has (FROM T TO U);
        """,
    )
    # Prerequirement: existing :T
    tid = uuid4()
    conn.execute("CREATE (t:T {id: $id}) RETURN t;", {"id": tid})

    # Merge :U from memory (new here, but might already exist)
    uid = uuid4()
    conn.execute(
        """
        MATCH (t:T {id: $tid}) // (1)
        MERGE (u:U {id: $uid}) // (2)
        SET u.name = $name     // (3)
        MERGE (t)-[e:has]->(u)
        RETURN t,u,e;
        """,
        {"tid": tid, "uid": uid, "name": "foo"},
    )

Some background for clarification: Goal was to construct a simple kind of object graph mapper (OGM) with MERGE: Given entities T,U with composite relation (:T)-[:has]->(:U), try to merge a new or existing U from memory. (1) ensures :T exists (2) merges an :U by its identifier (otherwise MERGE would try to create a new entity, if any property has changed) (3) update all :U properties in database (assuming object memory has most recent version or creates new entity)

Kuzu 0.4.2

sapalli2989 avatar May 17 '24 08:05 sapalli2989