Search code examples
sqlpostgresqlwhere-clause

PostgreSQL SQL Syntax


I have a where clause that looks like this (I didn't write this, it is old code from someone who is no longer here).

where alias_1.value <@ alias_2.value

What does the @ sign do? Is it really needed? Alias_2.value is NOT a parameter, but a column from a subquery.


Solution

  • It could be an array operator

    anyarray <@ anyarray → boolean
    

    Is the first array contained by the second?

    ARRAY[2,2,7] <@ ARRAY[1,7,4,2,6] → t
    

    Official docs for array operators and functions

    Or could be a range operator

    <@ range is contained by

    int4range(2,4) <@ int4range(1,7) → t
    

    <@ element is contained by

    42 <@ int4range(1,7) → f
    

    Docs for range operators and functions

    Or also could be a JSON operator

    jsonb <@ jsonb → boolean
    

    Is the first JSON value contained in the second?

    '{"b":2}'::jsonb <@ '{"a":1, "b":2}'::jsonb → t
    

    JSON Functions and Operators