Your code is twisted in several ways. Use instead
DO $do$ BEGIN IF EXISTS (SELECT 1 FROM function WHERE name = 'addition') THEN INSERT INTO function(id, name, description, function) SELECT max(id) + 1, 'subtraction', 'calculate', 'catalog' FROM function; RAISE NOTICE 'Whatever';
You should probably have a serial primary key by drawing the next value from SEQUENCE . What you have depends on race conditions and a typical anti-pattern.
Also, I would not use function as an identifier, even if it is allowed in Postgres. This is a reserved word in the SQL standard .
CREATE TABLE func func_id serial PRIMARY KEY , func text NOT NULL , description text , find_proper_name text) );
Then your target operator may be:
INSERT INTO func(func, description, find_proper_name) SELECT 'subtraction', 'calculate', 'catalog' WHERE EXISTS (SELECT 1 FROM func WHERE func = 'addition');
You don't need a DO statement at all.
source share