Re: Creating temp tables inside read only transactions

From: Darren Duncan <darren(at)darrenduncan(dot)net>
To: Guillaume Lelarge <guillaume(at)lelarge(dot)info>
Cc: mike beeper <mbeeper(at)hotmail(dot)com>, pgsql-general(at)postgresql(dot)org, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Creating temp tables inside read only transactions
Date: 2011-07-08 03:56:34
Message-ID: 4E167FF2.2060907@darrenduncan.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Guillaume Lelarge wrote [on pgsql-general]:
> On Thu, 2011-07-07 at 16:01 +0000, mike beeper wrote [on pgsql-general]:
>> I have a function that creates a temp table, populate it with results
>> during intermediate processing, and reads from it at the end. When
>> the transaction is marked as read only, it does not allow creation of
>> temp table, even though there are no permanent writes to the db. Are
>> there any workarounds? The following block errors out.
>>
>> SET TRANSACTION ISOLATION LEVEL READ COMMITTED READ ONLY;
>> create temp table test(test int);
>
> When you create a temporary table, PostgreSQL needs to add rows in
> pg_class, pg_attribute, and probably other system catalogs. So there are
> writes, which aren't possible in a read-only transaction. Hence the
> error. And no, there is no workaround.

That sounds like a deficiency to overcome.

It should be possible for those system catalogs to be virtual, defined like
union views over similar immutable tables for the read-only database plus
mutable in-memory ones for the temporary tables.

Are there any plans in the works to do this?

On the other hand, if one can have lexical-scope tables (table-typed routine
variables), and I know Pg 8.4+ has named subqueries which handle a lot of cases
where temp tables would otherwise be used, I would certainly expect those to
work when you're dealing with a readonly database.

-- Darren Duncan

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jeff Davis 2011-07-08 05:28:59 Re: [HACKERS] Creating temp tables inside read only transactions
Previous Message Joe Lester 2011-07-08 03:15:43 Re: failed archive command

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2011-07-08 04:31:31 proposal: new contrib module plpgsql's embeded sql validator
Previous Message Robert Haas 2011-07-08 02:00:10 Re: patch: Allow \dd to show constraint comments