#25 PostgreSQL – JSONB, contains operator to work with JSONB data. JSONB SQL. #shorts



#25 PostgreSQL – JSONB, contains operator to work with JSONB data. JSONB SQL. #shorts

#25 PostgreSQL - JSONB, contains operator to work with JSONB data.  JSONB SQL. #shorts

This video tutorial explaining the use of the contains operator in PostgreSQL to work with JSONB data

The first part of the code sets up a temporary table called temp2 with a single column json_value of type JSONB.

The insert statement adds a JSON value {“a”:1,”b”:2} into the json_value column of the temp2 table.

The next part of the code simply retrieves all rows from the temp2 table using select * from temp2.

The subsequent lines are comments that explain the purpose of the contains operator in PostgreSQL when working with JSONB data. It checks if the JSONB value on the left side is a subset of the JSONB value on the right side.

The following line select json_value contains ‘{“a”:1}’ from temp2 is an example of using the contains operator. It checks if the JSON value {“a”:1,”b”:2} is a subset of {“a”:1}. Since it contains the additional key-value pair “b”:2, the result would be false.

The line select ‘{“a”:1}’ contains json value from temp2 is another example using the contains operator. It checks if {“a”:1} is a subset of the JSON value in the

@SoftwareNuggets #softwarenuggets #shorts