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 TABLE people (
first_name TEXT,
last_name TEXT
);
CREATE OR REPLACE FUNCTION name(people) RETURNS text AS
$$
SELECT $1.first_name || ' ' || $1.last_name
$$ LANGUAGE SQL STRICT
IMMUTABLE
;
alter table people add column full_name text GENERATED ALWAYS AS (name(people)) STORED;
insert into people(first_name, last_name) values('John', 'Smith');
select full_name, full_name='John Smith' as pass from people;
1 rows affected
full_name | pass |
---|---|
John Smith | t |
CREATE OR REPLACE FUNCTION name(people) RETURNS text AS
$$
SELECT $1.first_name || ' ' || $1.last_name || ' function change'
$$ LANGUAGE SQL STRICT
IMMUTABLE
;
-- refresh generated column here
select full_name, full_name='John Smith function change' as pass from people;
full_name | pass |
---|---|
John Smith | f |