I have the following function on a postgres-database:
CREATE OR REPLACE FUNCTION getNearestPoints(float[], float[], float[], float[], int)
RETURNS SETOF record AS $$
DECLARE
i INT;
ret RECORD;
BEGIN
FOR i IN 1..$5 LOOP
FOR ret IN EXECUTE 'SELECT height, ST_Y(point), ST_X(point) FROM heights
WHERE ST_Intersects(ST_MakeEnvelope(' || $1[i] || ',' || $2[i] || ',' || $3[i] || ',' || $4[i] || ', 4326), point)' LOOP
RETURN NEXT ret;
END LOOP;
END LOOP;
RETURN;
END;
$$ LANGUAGE plpgsql;
I want to return default values to the record for each column (e.g. (-2000, -181, -181)), if the query returns no rows.
Coalesce with records doesn't seem to be possible.
How can I manage to do this?