[HACKERS] Check constraints on non-immutable keys

2010-06-30 Thread Magnus Hagander
We currently allow this: postgres=# create table t(a timestamptz not null primary key, check(a now())); NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index t_pkey for table t CREATE TABLE Which seems very wrong. For one thing, a dump of this database can not be restored if now() has

Re: [HACKERS] Check constraints on non-immutable keys

2010-06-30 Thread Tom Lane
Magnus Hagander mag...@hagander.net writes: Shouldn't we disallow anything that's not IMMUTABLE in a check constraint? I think you'd get too many howls of pain ... also, such a restriction is likely contrary to SQL spec. The example seems to me to be in the category of so don't do that rather

Re: [HACKERS] Check constraints on non-immutable keys

2010-06-30 Thread Magnus Hagander
On Wed, Jun 30, 2010 at 16:38, Tom Lane t...@sss.pgh.pa.us wrote: Magnus Hagander mag...@hagander.net writes: Shouldn't we disallow anything that's not IMMUTABLE in a check constraint? I think you'd get too many howls of pain ... also, such a restriction is likely contrary to SQL spec.

Re: [HACKERS] Check constraints on non-immutable keys

2010-06-30 Thread Tom Lane
Magnus Hagander mag...@hagander.net writes: On Wed, Jun 30, 2010 at 16:38, Tom Lane t...@sss.pgh.pa.us wrote: The example seems to me to be in the category of so don't do that rather than something that we need to save users from.  Yes, it's In that case, should we at least throw a warning?

Re: [HACKERS] Check constraints on non-immutable keys

2010-06-30 Thread Robert Haas
On Wed, Jun 30, 2010 at 11:02 AM, Tom Lane t...@sss.pgh.pa.us wrote: Magnus Hagander mag...@hagander.net writes: On Wed, Jun 30, 2010 at 16:38, Tom Lane t...@sss.pgh.pa.us wrote: The example seems to me to be in the category of so don't do that rather than something that we need to save users

Re: [HACKERS] Check constraints on non-immutable keys

2010-06-30 Thread Tom Lane
Robert Haas robertmh...@gmail.com writes: My scintillating contribution to this discussion is the observation that unrestorable dumps suck. No doubt, but is this a real problem in practice? I can't recall many field complaints about it. And the ones I do recall wouldn't have been prevented by

Re: [HACKERS] Check constraints on non-immutable keys

2010-06-30 Thread Robert Haas
On Wed, Jun 30, 2010 at 11:49 AM, Tom Lane t...@sss.pgh.pa.us wrote: Robert Haas robertmh...@gmail.com writes: My scintillating contribution to this discussion is the observation that unrestorable dumps suck. No doubt, but is this a real problem in practice? Magnus tells me that that was

Re: [HACKERS] Check constraints on non-immutable keys

2010-06-30 Thread Richard Huxton
On 30/06/10 17:11, Robert Haas wrote: On Wed, Jun 30, 2010 at 11:49 AM, Tom Lanet...@sss.pgh.pa.us wrote: Robert Haasrobertmh...@gmail.com writes: My scintillating contribution to this discussion is the observation that unrestorable dumps suck. No doubt, but is this a real problem in

Re: [HACKERS] Check constraints on non-immutable keys

2010-06-30 Thread Tom Lane
Robert Haas robertmh...@gmail.com writes: On Wed, Jun 30, 2010 at 11:49 AM, Tom Lane t...@sss.pgh.pa.us wrote: I can't recall many field complaints about it.  And the ones I do recall wouldn't have been prevented by a check as stupid as are there immutable functions in here. Hopefully there

Re: [HACKERS] Check constraints on non-immutable keys

2010-06-30 Thread Richard Huxton
On 30/06/10 18:11, Magnus Hagander wrote: On Wed, Jun 30, 2010 at 18:33, Richard Huxtond...@archonet.com wrote: IMHO The real solution would be something that could strip/rewrite the constraint on restore rather than trying to prevent people being stupid though. People *will* just tag their

Re: [HACKERS] Check constraints on non-immutable keys

2010-06-30 Thread Magnus Hagander
On Wed, Jun 30, 2010 at 18:33, Richard Huxton d...@archonet.com wrote: On 30/06/10 17:11, Robert Haas wrote: On Wed, Jun 30, 2010 at 11:49 AM, Tom Lanet...@sss.pgh.pa.us  wrote: Robert Haasrobertmh...@gmail.com  writes: My scintillating contribution to this discussion is the observation

Re: [HACKERS] Check constraints on non-immutable keys

2010-06-30 Thread Magnus Hagander
On Wed, Jun 30, 2010 at 19:16, Tom Lane t...@sss.pgh.pa.us wrote: Robert Haas robertmh...@gmail.com writes: On Wed, Jun 30, 2010 at 11:49 AM, Tom Lane t...@sss.pgh.pa.us wrote: I can't recall many field complaints about it.  And the ones I do recall wouldn't have been prevented by a check as

Re: [HACKERS] Check constraints on non-immutable keys

2010-06-30 Thread Merlin Moncure
On Wed, Jun 30, 2010 at 9:47 AM, Magnus Hagander mag...@hagander.net wrote: We currently allow this: postgres=# create table t(a timestamptz not null primary key, check(a now())); NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index t_pkey for table t CREATE TABLE Which seems

Re: [HACKERS] Check constraints on non-immutable keys

2010-06-30 Thread Tom Lane
Magnus Hagander mag...@hagander.net writes: On Wed, Jun 30, 2010 at 19:16, Tom Lane t...@sss.pgh.pa.us wrote: I concur with the thought that the most useful solution might be a way to tell pg_restore to remove or disable check constraints. Uh, say what? Are you saying pg_restore should

Re: [HACKERS] Check constraints on non-immutable keys

2010-06-30 Thread Magnus Hagander
On Wed, Jun 30, 2010 at 20:13, Tom Lane t...@sss.pgh.pa.us wrote: Magnus Hagander mag...@hagander.net writes: On Wed, Jun 30, 2010 at 19:16, Tom Lane t...@sss.pgh.pa.us wrote: I concur with the thought that the most useful solution might be a way to tell pg_restore to remove or disable check

Re: [HACKERS] Check constraints on non-immutable keys

2010-06-30 Thread Peter Eisentraut
On ons, 2010-06-30 at 10:38 -0400, Tom Lane wrote: Magnus Hagander mag...@hagander.net writes: Shouldn't we disallow anything that's not IMMUTABLE in a check constraint? I think you'd get too many howls of pain ... also, such a restriction is likely contrary to SQL spec. kibo The search

Re: [HACKERS] Check constraints on non-immutable keys

2010-06-30 Thread Tom Lane
Peter Eisentraut pete...@gmx.net writes: kibo The search condition shall simply contain a boolean value expression that is retrospectively deterministic. This is then defined in a rather complex manner that ends up disallowing col now() but allowing col now(). /kibo Oh, cute. Seems to

Re: [HACKERS] Check constraints on non-immutable keys

2010-06-30 Thread Robert Haas
On Wed, Jun 30, 2010 at 6:57 PM, Tom Lane t...@sss.pgh.pa.us wrote: Peter Eisentraut pete...@gmx.net writes: kibo The search condition shall simply contain a boolean value expression that is retrospectively deterministic. This is then defined in a rather complex manner that ends up

Re: [HACKERS] Check constraints on non-immutable keys

2010-06-30 Thread Chris Browne
mag...@hagander.net (Magnus Hagander) writes: I concur with the thought that the most useful solution might be a way to tell pg_restore to remove or disable check constraints. Uh, say what? Are you saying pg_restore should actually remove something from the database schema? And thus no longer

Re: [HACKERS] Check constraints on non-immutable keys

2010-06-30 Thread Tom Lane
Robert Haas robertmh...@gmail.com writes: On Wed, Jun 30, 2010 at 6:57 PM, Tom Lane t...@sss.pgh.pa.us wrote: The detailed definition is amazingly laborious and yet limited, though, as it basically doesn't address the problem except for that specific case and close relatives. Well, solving