Harry Yau <harry@aurasound.com.hk> writes:
> I am writing a pl/psql function with a temp table right now.
> It creates the temp table inside. Whenever I call this function in a
> session for the first time, it creates a shema, namely pg_temp_number,
> automatically and it creates the temp table within the schema. I've
> tried to add a check inside the function to check have the temp table
> been already existed.
Try something like
IF EXISTS(SELECT 1 FROM pg_class
WHERE relname = 'tablexxx' AND pg_table_is_visible(oid))
THEN ... drop it ...
The visibility check will reject temp tables belonging to other
sessions.
regards, tom lane