By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
Help with an interesting Postgres question: Why isn't an Index Only Scan used on a partition accessed via the parent table?.
CREATE FUNCTION my_func() RETURNS INTEGER AS $f$
BEGIN
IF current_setting('my.var',true)::int = 2 THEN
set my.var = 4;
RETURN current_setting('my.var');
ELSE
set my.var = 2;
RETURN current_setting('my.var');
END IF;
END;
$f$ LANGUAGE plpgsql;
select my_func();
CREATE FUNCTION
my_func |
---|
2 |
SELECT 1
select my_func();
select my_func();
select my_func();
my_func |
---|
4 |
SELECT 1
my_func |
---|
2 |
SELECT 1
my_func |
---|
4 |
SELECT 1