A row is represented by a composite type, like
CREATE TYPE mytype AS (
id integer,
name text,
fromdate timestamp with time zone
);
You can use such a type as function argument.
For each PostgreSQL table, there automatically exists a type with the same name and columns:
CREATE TABLE mytable (
id integer PRIMARY KEY,
name text,
fromdate timestamp with time zone NOT NULL
);
So you can create a function that takes an array of this type as argument:
CREATE OR REPLACE FUNCTION myfunc(arg mytable[]) RETURNS void
LANGUAGE plpgsql IMMUTABLE STRICT AS
$$DECLARE
t mytable;
BEGIN
FOREACH t IN ARRAY arg LOOP
RAISE NOTICE 'id = %', t.id;
END LOOP;
END;$$;
You can call it like this (assuming that there are two rows in mytable):
SELECT myfunc(array_agg(mytable)) FROM mytable;
NOTICE: id = 1
NOTICE: id = 2
┌────────┐
│ myfunc │
├────────┤
│ │
└────────┘
(1 row)
Alternatively, you can create a function that takes a cursor as argument:
CREATE OR REPLACE FUNCTION myfunc(arg refcursor) RETURNS void
LANGUAGE plpgsql IMMUTABLE STRICT AS
$$DECLARE
t mytable;
BEGIN
LOOP
FETCH NEXT FROM arg INTO t;
EXIT WHEN NOT FOUND;
RAISE NOTICE 'id = %', t.id;
END LOOP;
END;$$;
This can be called in a transaction as follows:
BEGIN;
DECLARE c CURSOR FOR SELECT * FROM mytable;
SELECT myfunc('c');
NOTICE: id = 1
NOTICE: id = 2
┌────────┐
│ myfunc │
├────────┤
│ │
└────────┘
(1 row)
COMMIT;