22.5. Checking a MAP Key (map_contains) #

This stored procedure must be executed inside a duckdb.query() call as Postgres Pro AXE does not support the MAP data type.

Required privileges: Postgres Pro AXE administrator only. For a full list of stored procedures and privileges, refer to Section 12.1.

Execute the following command on the Postgres Pro AXE server:

  SELECT * FROM duckdb.query('SELECT map_contains(MAP, key)') ON CONFLICT DO NOTHING;

Where:

  • MAP: The MAP data where the search must be performed.

    You can specify a column with the MAP data type or a MAP literal.

  • key: The key that must be searched.

Postgres Pro AXE returns true if the MAP data contains the specified key and false otherwise.

Example 22.5. Executing the map_contains Stored Procedure

MAP data in the data column of the map_table table:

 id |          data
----+-------------------------
  1 | {'a': 1, 'b': 2}

Checking MAP data for an existing key:

  SELECT * FROM duckdb.query('SELECT map_contains(data, ''a'') FROM map_table') ON CONFLICT DO NOTHING;
  true

Checking MAP data for a missing key:

  SELECT * FROM duckdb.query('SELECT map_contains(data, ''c'') FROM map_table') ON CONFLICT DO NOTHING;
  false