\set VERBOSITY verbose

-- 42804 DATATYPE MISMATCH
VALUES (1, 2), (3, 4) EXCEPT VALUES (1, 'foo'), (3, 'bar');

-- 42601 SYNTAX ERROR
VALUES (1, 2), (3, 4) EXCEPT VALUES (1), (3);

CREATE OR REPLACE FUNCTION results_eq(refcursor, refcursor)
RETURNS BOOLEAN AS $$
DECLARE
    have      ALIAS FOR $1;
    want      ALIAS FOR $2;
    rec_have  RECORD;
    rec_want  RECORD;
BEGIN
    FETCH have INTO rec_have;
    FETCH want INTO rec_want;
    WHILE rec_have IS NOT NULL OR rec_want IS NOT NULL LOOP
        IF rec_have IS DISTINCT FROM rec_want THEN RETURN FALSE; END IF;
        FETCH have INTO rec_have;
        FETCH want INTO rec_want;
    END LOOP;

    RETURN TRUE;
END;
$$ LANGUAGE plpgsql;

BEGIN;
DECLARE cwant CURSOR FOR VALUES (1, 2), (3, 4);
DECLARE chave CURSOR FOR VALUES (1, 'foo'), (3, 'bar');
-- 42804 DATATYPE MISMATCH
SELECT results_eq( 'cwant'::refcursor, 'chave'::refcursor );
ROLLBACK;

BEGIN;
DECLARE cwant2 CURSOR FOR VALUES (1, 2), (3, 4);
DECLARE chave2 CURSOR FOR VALUES (1), (3);
-- 42804 DATATYPE MISMATCH???
SELECT results_eq( 'cwant2'::refcursor, 'chave2'::refcursor );
ROLLBACK;

DROP FUNCTION results_eq(refcursor, refcursor);