Hoogle Search

Within LTS Haskell 24.38 (ghc-9.10.3)

Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.

  1. (--.) :: JSONBExpr a -> [Text] -> JSONBExpr b

    esqueleto Database.Esqueleto.PostgreSQL.JSON

    Requires PostgreSQL version >= 10 Removes a set of keys from an object, or string elements from an array. This is the same operator internally as -., but the option to use a text array, instead of text or integer was only added in version 10. That's why this function is seperate from -. NOTE: The following is equivalent:

    {some JSON expression} -. "a" -. "b"
    
    is equivalent to
    {some JSON expression} --. ["a","b"]
    

    PostgreSQL Documentation

    | Type    | Description                                                            |  Example
    ---+---------+------------------------------------------------------------------------+-------------------------------------------------
    - | text[]  | Delete multiple key/value pairs or string elements from left operand.  | '{"a": "b", "c": "d"}'::jsonb - '{a,c}'::text[]
    |         | Key/value pairs are matched based on their key value.                  |
    

  2. (-.) :: JSONBExpr a -> JSONAccessor -> JSONBExpr b

    esqueleto Database.Esqueleto.PostgreSQL.JSON

    Requires PostgreSQL version >= 9.5 This operator can remove a key from an object or a string element from an array when using text, and remove certain elements by index from an array when using integers. Negative integers delete counting from the end of the array. (e.g. -1 being the last element, -2 being the second to last, etc.) CAUTION: THIS FUNCTION THROWS AN EXCEPTION WHEN USED ON ANYTHING OTHER THAN OBJECTS OR ARRAYS WHEN USING TEXT, AND ANYTHING OTHER THAN ARRAYS WHEN USING INTEGERS!

    Objects and arrays

    {"a": 3.14}            - "a"         == {}
    {"a": "b"}             - "b"         == {"a": "b"}
    {"a": 3.14}            - "a"         == {}
    {"a": 3.14, "c": true} - "a"         == {"c": true}
    ["a", 2, "c"]          - "a"         == [2, "c"] -- can remove strings from arrays
    [true, "b", 5]         - 0           == ["b", 5]
    [true, "b", 5]         - 3           == [true, "b", 5]
    [true, "b", 5]         - -1          == [true, "b"]
    [true, "b", 5]         - -4          == [true, "b", 5]
    []                     - 1           == []
    {"1": true}            - 1           == ERROR: cannot delete from object using integer index
    1                      - <anything>  == ERROR: cannot delete from scalar
    "a"                    - <anything>  == ERROR: cannot delete from scalar
    true                   - <anything>  == ERROR: cannot delete from scalar
    null                   - <anything>  == ERROR: cannot delete from scalar
    

    PostgreSQL Documentation

    | Type    | Description                                                            |  Example
    ---+---------+------------------------------------------------------------------------+-------------------------------------------------
    - | text    | Delete key/value pair or string element from left operand.             | '{"a": "b"}'::jsonb - a
    |         | Key/value pairs are matched based on their key value.                  |
    - | integer | Delete the array element with specified index (Negative integers count | '["a", "b"]'::jsonb - 1
    |         | from the end). Throws an error if top level container is not an array. |
    

  3. (->.) :: JSONBExpr a -> JSONAccessor -> JSONBExpr b

    esqueleto Database.Esqueleto.PostgreSQL.JSON

    Requires PostgreSQL version >= 9.3 This function extracts the jsonb value from a JSON array or object, depending on whether you use an int or a text. (cf. JSONAccessor) As long as the left operand is jsonb, this function will not throw an exception, but will return NULL when an int is used on anything other than a JSON array, or a text is used on anything other than a JSON object.

    PostgreSQL Documentation

    | Type | Description                                |  Example                                         | Example Result
    ----+------+--------------------------------------------+--------------------------------------------------+----------------
    -> | int  | Get JSON array element (indexed from zero) | '[{"a":"foo"},{"b":"bar"},{"c":"baz"}]'::json->2 | {"c":"baz"}
    -> | text | Get JSON object field by key               | '{"a": {"b":"foo"}}'::json->a                  | {"b":"foo"}
    

  4. (->>.) :: JSONBExpr a -> JSONAccessor -> SqlExpr (Value (Maybe Text))

    esqueleto Database.Esqueleto.PostgreSQL.JSON

    Requires PostgreSQL version >= 9.3 Identical to ->., but the resulting DB type is a text, so it could be chained with anything that uses text. CAUTION: if the "scalar" JSON value null is the result of this function, PostgreSQL will interpret it as a PostgreSQL NULL value, and will therefore be Nothing instead of (Just "null")

    PostgreSQL Documentation

    | Type | Description                    |  Example                    | Example Result
    -----+------+--------------------------------+-----------------------------+----------------
    ->> | int  | Get JSON array element as text | '[1,2,3]'::json->>2         | 3
    ->> | text | Get JSON object field as text  | '{"a":1,"b":2}'::json->>b | 2
    

  5. (<@.) :: JSONBExpr a -> JSONBExpr b -> SqlExpr (Value Bool)

    esqueleto Database.Esqueleto.PostgreSQL.JSON

    Requires PostgreSQL version >= 9.4 This operator works the same as @>., just with the arguments flipped. So it checks for the JSON value on the left to be a subset of JSON value on the right. Examples of the usage of this operator can be found in the Database.Persist.Postgresql.JSON module. (here: https://hackage.haskell.org/package/persistent-postgresql-2.10.0/docs/Database-Persist-Postgresql-JSON.html)

    PostgreSQL Documentation

    | Type  | Description                                              |  Example
    ----+-------+----------------------------------------------------------+---------------------------------------------
    <@ | jsonb | Is the left JSON value contained within the right value? | '{"b":2}'::jsonb <@ '{"a":1, "b":2}'::jsonb
    

  6. (?&.) :: JSONBExpr a -> [Text] -> SqlExpr (Value Bool)

    esqueleto Database.Esqueleto.PostgreSQL.JSON

    Requires PostgreSQL version >= 9.4 This operator checks if ALL of the given texts are top-level members of the JSON value on the left. This means a top-level field in an object, a top-level string in an array or just a string value. Examples of the usage of this operator can be found in the Database.Persist.Postgresql.JSON module. (here: https://hackage.haskell.org/package/persistent-postgresql-2.10.0/docs/Database-Persist-Postgresql-JSON.html)

    PostgreSQL Documentation

    | Type   | Description                                            |  Example
    ----+--------+--------------------------------------------------------+----------------------------------------
    ?& | text[] | Do all of these array strings exist as top-level keys? | '["a", "b"]'::jsonb ?& array[a, b]
    

  7. (?.) :: JSONBExpr a -> Text -> SqlExpr (Value Bool)

    esqueleto Database.Esqueleto.PostgreSQL.JSON

    Requires PostgreSQL version >= 9.4 This operator checks if the given text is a top-level member of the JSON value on the left. This means a top-level field in an object, a top-level string in an array or just a string value. Examples of the usage of this operator can be found in the Database.Persist.Postgresql.JSON module. (here: https://hackage.haskell.org/package/persistent-postgresql-2.10.0/docs/Database-Persist-Postgresql-JSON.html)

    PostgreSQL Documentation

    | Type | Description                                                     |  Example
    ---+------+-----------------------------------------------------------------+-------------------------------
    ? | text | Does the string exist as a top-level key within the JSON value? | '{"a":1, "b":2}'::jsonb ? b
    

  8. (?|.) :: JSONBExpr a -> [Text] -> SqlExpr (Value Bool)

    esqueleto Database.Esqueleto.PostgreSQL.JSON

    Requires PostgreSQL version >= 9.4 This operator checks if ANY of the given texts is a top-level member of the JSON value on the left. This means any top-level field in an object, any top-level string in an array or just a string value. Examples of the usage of this operator can be found in the Database.Persist.Postgresql.JSON module. (here: https://hackage.haskell.org/package/persistent-postgresql-2.10.0/docs/Database-Persist-Postgresql-JSON.html)

    PostgreSQL Documentation

    | Type   | Description                                            |  Example
    ----+--------+--------------------------------------------------------+---------------------------------------------------
    ?| | text[] | Do any of these array strings exist as top-level keys? | '{"a":1, "b":2, "c":3}'::jsonb ?| array[b, c]
    

  9. (@>.) :: JSONBExpr a -> JSONBExpr b -> SqlExpr (Value Bool)

    esqueleto Database.Esqueleto.PostgreSQL.JSON

    Requires PostgreSQL version >= 9.4 This operator checks for the JSON value on the right to be a subset of the JSON value on the left. Examples of the usage of this operator can be found in the Database.Persist.Postgresql.JSON module. (here: https://hackage.haskell.org/package/persistent-postgresql-2.10.0/docs/Database-Persist-Postgresql-JSON.html)

    PostgreSQL Documentation

    | Type  | Description                                                 |  Example
    ----+-------+-------------------------------------------------------------+---------------------------------------------
    @> | jsonb | Does the left JSON value contain within it the right value? | '{"a":1, "b":2}'::jsonb @> '{"b":2}'::jsonb
    

  10. (||.) :: JSONBExpr a -> JSONBExpr b -> JSONBExpr c

    esqueleto Database.Esqueleto.PostgreSQL.JSON

    Requires PostgreSQL version >= 9.5 This operator concatenates two JSON values. The behaviour is self-evident when used on two arrays, but the behaviour on different combinations of JSON values might behave unexpectedly. CAUTION: THIS FUNCTION THROWS AN EXCEPTION WHEN CONCATENATING A JSON OBJECT WITH A JSON SCALAR VALUE!

    Arrays

    This operator is a standard concatenation function when used on arrays:
    [1,2]   || [2,3]   == [1,2,2,3]
    []      || [1,2,3] == [1,2,3]
    [1,2,3] || []      == [1,2,3]
    

    Objects

    When concatenating JSON objects with other JSON objects, the fields from the JSON object on the right are added to the JSON object on the left. When concatenating a JSON object with a JSON array, the object will be inserted into the array; either on the left or right, depending on the position relative to the operator. When concatening an object with a scalar value, an exception is thrown.
    {"a": 3.14}                    || {"b": true}         == {"a": 3.14, "b": true}
    {"a": "b"}                     || {"a": null}         == {"a": null}
    {"a": {"b": true, "c": false}} || {"a": {"b": false}} == {"a": {"b": false}}
    {"a": 3.14}                    || [1,null]            == [{"a": 3.14},1,null]
    [1,null]                       || {"a": 3.14}         == [1,null,{"a": 3.14}]
    1                              || {"a": 3.14}         == ERROR: invalid concatenation of jsonb objects
    {"a": 3.14}                    || false               == ERROR: invalid concatenation of jsonb objects
    

    Scalar values

    Scalar values can be thought of as being singleton arrays when used with this operator. This rule does not apply when concatenating with JSON objects.
    1          || null       == [1,null]
    true       || "a"        == [true,"a"]
    [1,2]      || false      == [1,2,false]
    null       || [1,"a"]    == [null,1,"a"]
    {"a":3.14} || true       == ERROR: invalid concatenation of jsonb objects
    3.14       || {"a":3.14} == ERROR: invalid concatenation of jsonb objects
    {"a":3.14} || [true]     == [{"a":3.14},true]
    [false]    || {"a":3.14} == [false,{"a":3.14}]
    

    PostgreSQL Documentation

    | Type  | Description                                         |  Example
    ----+-------+-----------------------------------------------------+--------------------------------------------
    || | jsonb | Concatenate two jsonb values into a new jsonb value | '["a", "b"]'::jsonb || '["c", "d"]'::jsonb
    
    Note: The || operator concatenates the elements at the top level of each of its operands. It does not operate recursively. For example, if both operands are objects with a common key field name, the value of the field in the result will just be the value from the right hand operand.

Page 124 of many | Previous | Next