2

I'm trying to perform a query that evaluates if an array includes or contains a specif value or set of values.

SELECT * FROM table WHERE data = ['value_a']

https://surrealdb.com/docs/surrealql/statements/select

I've read the documentation and try several queries, but I didn't find any function or way to create this query.

I've read the official documentation and performed several queries based on the examples, but nothing have worked.

https://surrealdb.com/docs/surrealql/statements/select

My expected behaviour is:

Matches a specific value or set of values like these examples in SQL relational database.

https://www.w3schools.com/sql/sql_in.asp

codesandtags
  • 382
  • 2
  • 8

2 Answers2

4

There is a CONTAINS operator : https://surrealdb.com/docs/surrealql/operators#contains

The Query should be like:

SELECT * FROM table WHERE data CONTAINS 'value_a'
RusArtM
  • 1,116
  • 3
  • 15
  • 22
Fabian
  • 41
  • 2
1

Lets say you have records in SurrealDB lookslike this:

[
    {
        email: 'jan@test3.co.za',
        firstname: 'Jan',
        id: person:0b3b952c565155fcb0ae9acfedf99315,
        lastname: 'Brand',
        program: [
            'flights',
            'apps'
        ]
    },
    {
        email: 'sam@test3.co.za',
        firstname: 'Sam',
        id: person:8bc35665018b595b95bd9b2e909ed651,
        lastname: 'pedlar',
        program: [
            'entertainment'
        ]
    }
]

You want to select the record where the 'program' array contains the value 'apps', then you can use the following statement:

select * from person where program contains 'apps';

You will then get the following answer:

{
    email: 'jan@test3.co.za',
    firstname: 'Jan',
    id: person:0b3b952c565155fcb0ae9acfedf99315,
    lastname: 'Brand',
    program: [
        'flights',
        'apps'
    ]
}
TuinBoy
  • 185
  • 1
  • 9