Philip,
"session variables" is the perfect name for this kind of use; and
googling it up some times ago lead me to
a) a temp table implementation
b) some shared memory implementation
of these I can present you with a), written to store an integer
user-ID; you can adjust it accordingly:
CREATE OR REPLACE FUNCTION set_user(myid_user integer)
RETURNS integer AS
$BODY$
BEGIN
perform relname from pg_class
where relname = 'icke_tmp'
and case when has_schema_privilege(relnamespace, 'USAGE')
then pg_table_is_visible(oid) else false end;
if not found then
create temporary table icke_tmp (
id_user integer
);
else
delete from icke_tmp;
end if;
insert into icke_tmp values (myid_user);
RETURN 0;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
CREATE OR REPLACE FUNCTION get_user()
RETURNS integer AS
$BODY$
declare
ergebnis int4;
BEGIN
perform relname from pg_class
where relname = 'icke_tmp'
and case when has_schema_privilege(relnamespace, 'USAGE')
then pg_table_is_visible(oid) else false end;
if not found then
return 0;
else
select id_user from icke_tmp into ergebnis;
end if;
if not found then
ergebnis:=0;
end if;
RETURN ergebnis;
END;
$BODY$
LANGUAGE 'plpgsql' STABLE
COST 100;
You can adjust that "0" to NULL or whatever should be the default for
your application. In mine I default to 0; with 0 being something like
"testuser".
best wishes,
Harald
--
GHUM Harald Massa
persuadere et programmare
Harald Armin Massa
Spielberger Straße 49
70435 Stuttgart
0173/9409607
no fx, no carrier pigeon
-
EuroPython 2009 will take place in Birmingham - Stay tuned!