22.1. Retrieving the Size of MAP Data (cardinality) #

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 cardinality(MAP)') ON CONFLICT DO NOTHING;

Where MAP is the MAP data whose size must be retrieved.

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

Postgres Pro AXE returns the number of key-value pairs in the MAP data.

Example 22.1. Executing the cardinality Stored Procedure

Retrieving the size of MAP data with key-value pairs:

  SELECT * FROM duckdb.query('SELECT cardinality(MAP {''a'': 1, ''b'': 2, ''c'': 3})') ON CONFLICT DO NOTHING;
  3

Retrieving the size of empty MAP data:

  SELECT * FROM duckdb.query('SELECT cardinality(MAP {})') ON CONFLICT DO NOTHING;
  0

MAP data in the data column of the map_table table:

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

Retrieving the size of MAP data from a column:

  SELECT * FROM duckdb.query('SELECT cardinality(data) FROM map_table') ON CONFLICT DO NOTHING;
  3