Pass additional data in connection for use by PGSQL Trigger
Old question, but still valid, so here is what I ended up using.
On 9.6 and above, to set the values either of the following will work:

select set_config('app.userid', '3', true)
SET LOCAL &quot;app.userid&quot; = 3; (or '3')

To read the value out,

select current_value('app.userid')

I ended up wrapping the lookup for the userid or other field in a function, to handle the type conversion(s) and the fact that it might not be set:
CREATE OR REPLACE FUNCTION app_get_userid() RETURNS INT AS $$
DECLARE userid integer;
BEGIN
    BEGIN
        userid := current_setting('app.userid');
    EXCEPTION
        WHEN OTHERS THEN userid := NULL;
    END;
    return userid;
END;
$$ LANGUAGE plpgsql;