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: $parent doesn't work in if statement in subquery #3960

Open
2 tasks done
agufagit opened this issue Apr 28, 2024 · 2 comments
Open
2 tasks done

Bug: $parent doesn't work in if statement in subquery #3960

agufagit opened this issue Apr 28, 2024 · 2 comments
Labels
question Further information is requested

Comments

@agufagit
Copy link

Describe the bug

$parent doesn't work in if statement in subquery

Steps to reproduce

nothing returns

select 1 from [{id: 1}] WHERE (SELECT true FROM 1 WHERE (IF 1=1 then $parent.id=1 else false end)) 

Expected behaviour

returns

[
    {
        "1": 1
    }
]

SurrealDB version

surreal 1.4.0

Contact Details

No response

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
@agufagit agufagit added bug Something isn't working triage This issue is new labels Apr 28, 2024
@phughk
Copy link
Contributor

phughk commented May 13, 2024

Hey @agufagit , this is because your subquery IF 1=1 then $parent.id=1 else false end is evaluating the expression $parent.id=1 instead of returning it. So the outter expression SELECT true FROM 1 WHERE ... will result in SELECT true FROM 1 WHERE true which won't return anything. I think - could be wrong.
Please let us know if that solves the issue.

@phughk phughk added question Further information is requested and removed bug Something isn't working triage This issue is new labels May 13, 2024
@agufagit
Copy link
Author

let me rewrite this query

select 1 from [{id: 1}] WHERE array::len(SELECT true FROM 1 WHERE (IF 1=1 then $parent.id=1 else false end)) > 0

SELECT true FROM 1 where true does return

[
    {
        "true": true
    }
]

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

No branches or pull requests

2 participants