I try to write a function to insert some values in column3
in my table based on values inside this table, but I'm not so familiar with writing functions in Postgresql 9.6.
--Create some table
CREATE TABLE test(column1 INT, column2 INT, column3 TEXT)
INSERT INTO test VALUES(-8020,15),(-200,1),(23,115)
--Build function
CREATE OR REPLACE FUNCTION new_function()
RETURNS TEXT AS
$$
BEGIN
IF test(column1) <= -7000 THEN INSERT INTO test(column3) VALUES('small');
ELSIF test(column1) >= -7000 AND test(column2) <= 15 THEN INSERT INTO test(column3) VALUES('nohello');
ELSIF test(column1) >= -7000 ANDtable(column2) >= 15 THEN INSERT INTO test(column3) VALUES('test');
ELSE INSERT INTO test(column6) VALUES("nodata");
END IF;
END;
$$
LANGUAGE plpgsql;
The result should be a table that looks like this:
Column1 | Column2 | Column3
---------------------------
-8020 | 15 | small
-200 | 1 | nohello
23 | 115 | test
While calling new_function
I get the error column1 doesn't exist.