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

Bug: Edge inserted via INSERT cannot be queried with -> #3247

Closed
2 tasks done
avoonix opened this issue Jan 2, 2024 · 2 comments · Fixed by #4057
Closed
2 tasks done

Bug: Edge inserted via INSERT cannot be queried with -> #3247

avoonix opened this issue Jan 2, 2024 · 2 comments · Fixed by #4057
Labels
bug Something isn't working topic:schema This is related to schema definition and enforcement topic:surrealql This is related to the SurrealQL query language

Comments

@avoonix
Copy link

avoonix commented Jan 2, 2024

Describe the bug

I am using INSERT instead of RELATE because I am inserting many relationships at once and some relations may already exist (INSERT IGNORE INTO tagged ($values) where $values is an array of {in: thing, out: thing). The resulting table looks the same as if I had used RELATE, but querying does not work as intended.

If this is intended, then a warning should be added to the documentation that even though the result of adding a edge via INSERT looks identical to RELATE, the INSERTed edges cannot be queried with ->.

Steps to reproduce

I add tags and images to the database, and tag image 1 and 3 with car, but only image 3 is picked up by the -> queries:

update tag:smile set name = "smile";
update tag:car set name = "car";

update image:1 set path = "images/1.png";
update image:2 set path = "images/2.png";
update image:3 set path = "images/3.png";

# using insert because I can pass an array of relationships, which is not possible with relate
insert into tagged ({in: image:1, out: tag:car});
relate image:3->tagged->tag:car;

both have the same structure

select * from tagged;
[
    {
        "id": "tagged:62fe7dnbu0dwszryw1rl",
        "in": "image:1",
        "out": "tag:car"
    },
    {
        "id": "tagged:ttj5k4nop8dttddqafyb",
        "in": "image:3",
        "out": "tag:car"
    }
]

select all images that do not have any tags; this returns image 1 and 2 - it should only return image 2

SELECT * FROM image WHERE count(->tagged->tag) = 0;
[
    {
        "id": "image:1",
        "path": "images/1.png"
    },
    {
        "id": "image:2",
        "path": "images/2.png"
    }
]

select all images that have the car tag; this returns image 3 - it should also return image 1

select * from image where ->tagged->(tag where name = "car");
[
    {
        "id": "image:3",
        "path": "images/3.png"
    }
]

Expected behaviour

See comments in "steps to reproduce"

SurrealDB version

1.0.2 rust crate (not using the server, but embedded)

Contact Details

github

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct
@avoonix avoonix added bug Something isn't working triage This issue is new labels Jan 2, 2024
@phughk
Copy link
Contributor

phughk commented Jan 5, 2024

Thanks for raising! Couple of this

  • we don't really support insert this way, as we may change or do additional checks on relate tables in the future. For now it is a convenient workaround, thanks for sharing
  • The select is likely a problem not with the RELATE but the actual implementation of the SELECT. We will need to have a look at this cc @DelSkayn

Would you like to join us on Developer Office Hours (Friday 1600 GMT) to discuss? It may be helpful to understand better how this is happening.

@phughk phughk self-assigned this Jan 5, 2024
@phughk phughk removed the triage This issue is new label Jan 5, 2024
@AlbertMarashi
Copy link

AlbertMarashi commented Jan 12, 2024

I just ran into this really annoying bug, I was creating a relation using create instead of relate in surrealist for testing and the select happened to fail as a result, I was almost about to give up on surrealdb because of this 💀

@kearfy kearfy added topic:surrealql This is related to the SurrealQL query language topic:schema This is related to schema definition and enforcement labels Jan 16, 2024
@kearfy kearfy linked a pull request Jan 18, 2024 that will close this issue
1 task
@RaphaelDarley RaphaelDarley mentioned this issue Apr 5, 2024
3 tasks
@kearfy kearfy mentioned this issue May 17, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working topic:schema This is related to schema definition and enforcement topic:surrealql This is related to the SurrealQL query language
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants