timescaledb/test/sql/baserel_cache.sql
Alexander Kuzmenkov 1cc8c15cad Do not clobber the baserel cache on UDF error
The baserel cache should only be allocated and freed by the top-level
query.
2022-11-01 18:01:26 +04:00

28 lines
782 B
PL/PgSQL

-- This file and its contents are licensed under the Apache License 2.0.
-- Please see the included NOTICE for copyright information and
-- LICENSE-APACHE for a copy of the license.
-- Test that the baserel cache is not clobbered if there's an error
-- in a SQL function.
CREATE TABLE valid_ids
(
id UUID PRIMARY KEY
);
CREATE FUNCTION DEFAULT_UUID(TEXT DEFAULT '') RETURNS UUID AS $$
BEGIN
RETURN COALESCE($1, '')::UUID;
EXCEPTION WHEN invalid_text_representation THEN
RETURN '00000000-0000-0000-0000-000000000000';
END;
$$ LANGUAGE PLPGSQL IMMUTABLE;
CREATE FUNCTION KNOWN_ID(UUID, TEXT) RETURNS UUID AS $$
SELECT COALESCE(
(SELECT id FROM valid_ids WHERE id = $1),
DEFAULT_UUID()
);
$$ LANGUAGE SQL;
SELECT KNOWN_ID(NULL, ''), KNOWN_ID(NULL, '');