Hi
Since I havent created functions before myself, I need a bit help here...
I want to create a function in Postgres 8.0 that can take multiple rows and copy those into another table (table2) that has same field/properties as table1; Like a backup.
Only thing, if row exists in table2, nothing should happen to that row.
I've stfw and but cant seem to find anything real good 🙁
Im guessing something like this, but still missing "if row exists, skip" :
CREATE OR REPLACE FUNCTION public."saveTimeRange"(startTime int4, endTime int4, prop1 int4, prop2 int4)
RETURNS BOOLEAN
$BODY$DECLARE
BEGIN
IF ((startTime > 0) AND (endTime > 0) AND (startTime < endTime) AND (prop1 > 0) AND (prop2 > 0)) THEN
INSERT INTO public."table2"
SELECT *
FROM public."table1"
WHERE (
"time_stamp" >= startTime
AND
"time_stamp" <= endTime
AND
"property1" = prop1
AND
"property2" = prop2
)
ORDER BY "time_stamp" DESC;
RETURN 1;
END IF;
RETURN 0;
END$BODY$
LANGUAGE 'plpgsql' VOLATILE SECURITY DEFINER;
ALTER FUNCTION public."saveTimeRange"(startTime int4, endTime int4, prop1 int4, prop2 int4) OWNER TO postgres;