/* contrib/pg_variables/pg_variables--1.2--1.3.sql */

-- complain if script is sourced in psql, rather than via ALTER EXTENSION
\echo Use "ALTER EXTENSION pg_variables UPDATE TO '1.3'" to load this file. \quit

-- Functions work with collection variables with integer or text key and any value

CREATE FUNCTION pgv_set_elem(package text, name text, key int, value anyelement, is_transactional bool default false)
RETURNS void
AS 'MODULE_PATHNAME', 'collection_set'
LANGUAGE C VOLATILE;

CREATE FUNCTION pgv_set_elem(package text, name text, key text, value anyelement, is_transactional bool default false)
RETURNS void
AS 'MODULE_PATHNAME', 'collection_set'
LANGUAGE C VOLATILE;

CREATE FUNCTION pgv_get_elem(package text, name text, key int, val_type anyelement)
RETURNS anyelement
AS 'MODULE_PATHNAME', 'collection_get'
LANGUAGE C VOLATILE;

CREATE FUNCTION pgv_get_elem(package text, name text, key text, val_type anyelement)
RETURNS anyelement
AS 'MODULE_PATHNAME', 'collection_get'
LANGUAGE C VOLATILE;

CREATE FUNCTION pgv_exists_elem(package text, name text, key int)
RETURNS bool
AS 'MODULE_PATHNAME', 'collection_exists'
LANGUAGE C VOLATILE;

CREATE FUNCTION pgv_exists_elem(package text, name text, key text)
RETURNS bool
AS 'MODULE_PATHNAME', 'collection_exists'
LANGUAGE C VOLATILE;

CREATE FUNCTION pgv_remove_elem(package text, name text, key int)
RETURNS void
AS 'MODULE_PATHNAME', 'variable_delete'
LANGUAGE C VOLATILE;

CREATE FUNCTION pgv_remove_elem(package text, name text, key text)
RETURNS void
AS 'MODULE_PATHNAME', 'variable_delete'
LANGUAGE C VOLATILE;

-- Functions to work with collection iterators

CREATE FUNCTION pgv_first(package text, name text, key_type anyelement)
RETURNS anyelement
AS 'MODULE_PATHNAME', 'iterator_first'
LANGUAGE C VOLATILE;

CREATE FUNCTION pgv_last(package text, name text, key_type anyelement)
RETURNS anyelement
AS 'MODULE_PATHNAME', 'iterator_last'
LANGUAGE C VOLATILE;

CREATE FUNCTION pgv_next(package text, name text, key anyelement)
RETURNS anyelement
AS 'MODULE_PATHNAME', 'iterator_next'
LANGUAGE C VOLATILE;

CREATE FUNCTION pgv_prior(package text, name text, key anyelement)
RETURNS anyelement
AS 'MODULE_PATHNAME', 'iterator_prior'
LANGUAGE C VOLATILE;

CREATE FUNCTION pgv_count(package text, name text)
RETURNS integer
AS 'MODULE_PATHNAME', 'iterator_count'
LANGUAGE C VOLATILE;
