Re: Singleton table (was Re: How to don't update sequence on rollback of a transaction) - Mailing list pgsql-general

From Craig Ringer
Subject Re: Singleton table (was Re: How to don't update sequence on rollback of a transaction)
Date
Msg-id 501B6344.20607@ringerc.id.au
Whole thread Raw
List pgsql-general
On 08/03/2012 12:07 PM, Chris Angelico wrote:
> On Fri, Aug 3, 2012 at 10:00 AM, Craig Ringer <ringerc@ringerc.id.au> wrote:
>> -- PostgreSQL specific hack you can use to make
>> -- really sure only one row ever exists
>> CREATE UNIQUE INDEX there_can_be_only_one
>> ON invoice_number( (1) );
> This will guarantee that there's only one row. Does Postgres then
> optimize anything based on this? I have a couple of cases where I'm
> using a table to store global configuration, and selecting/updating
> that table without a WHERE clause to manipulate it. Can PostgreSQL
> notice the "highlander" status of the table and know not to go looking
> for more?

As far as I know, no. If anything it could slow things down a tad. I
just like to be really sure it's a single row table.

An `ON INSERT OR DELETE` trigger that throws is probably a more sensible
option, really.

--
Craig Ringer

pgsql-general by date:

Previous
From: Craig Ringer
Date:
Subject: Re: How to don't update sequence on rollback of a transaction
Next
From: Condor
Date:
Subject: Re: Need help with SQL query and finding NULL array_agg