Re: [BUGS] BUG #6612: Functions can be called inside CHECK statements

2012-04-25 Thread Tom Lane
Ari Entlich writes: > I do, however, think it should definitely be documented somewhere that > functions cannot be used to get around the lack of check statement > subqueries, because the ordering of operations is wrong. That statement seems to me to be complete nonsense. You can certainly pu

Re: [BUGS] BUG #6612: Functions can be called inside CHECK statements

2012-04-25 Thread Ari Entlich
Wow, so I guess I'm pretty much wrong about this... Sorry for the noise guys. I failed to consider different uses for functions, obviously, and it's not possible to automatically detect usages which could cause problems. Perhaps this is more of a bug in the documentation than anything else. I c

Re: [BUGS] BUG #6612: Functions can be called inside CHECK statements

2012-04-25 Thread Tom Lane
Greg Stark writes: > On Wed, Apr 25, 2012 at 4:06 PM, Kevin Grittner > wrote: >> A CHECK constraint using a volatile function is potentially valid >> and useful, IMO. > Hm. I suppose it depends on what you think a constraint is. I had > always thought it was a guarantee that all the data in the

Re: [BUGS] BUG #6612: Functions can be called inside CHECK statements

2012-04-25 Thread Greg Stark
On Wed, Apr 25, 2012 at 4:06 PM, Kevin Grittner wrote: > A CHECK constraint using a volatile function is potentially valid > and useful, IMO.  Think about a column which is supposed to record > the moment of an event which has occurred.  It could make sense to > ensure that the timestamptz value i

Re: [BUGS] BUG #6612: Functions can be called inside CHECK statements

2012-04-25 Thread Tom Lane
"Kevin Grittner" writes: > Greg Stark wrote: >> Only IMMUTABLE functions can be used in CHECK constraints. > It doesn't look like that to me: No, we have never enforced that. IIRC the idea has been discussed, but we thought that adding the restriction would break too many existing application

Re: [BUGS] BUG #6612: Functions can be called inside CHECK statements

2012-04-25 Thread Kevin Grittner
Greg Stark wrote: > Only IMMUTABLE functions can be used in CHECK constraints. > It's a feature that expressions including subqueries are > automatically detected as not being immutable and automatically > barred. It doesn't look like that to me: test=# create function xxx() returns text vol

Re: [BUGS] BUG #6612: Functions can be called inside CHECK statements

2012-04-25 Thread Greg Stark
On Wed, Apr 25, 2012 at 11:33 AM, wrote: > Seeing as Postgres does not allow sub-queries in CHECK constraints yet, it > doesn't make any sense to me for it to allow function calls, since functions > can perform queries. This is why functions must be marked as one of VOLATILE, STABLE, or IMMUTABL

Re: [BUGS] BUG #6612: Functions can be called inside CHECK statements

2012-04-25 Thread hubert depesz lubaczewski
On Wed, Apr 25, 2012 at 10:33:10AM +, atrig...@ccs.neu.edu wrote: > Seeing as Postgres does not allow sub-queries in CHECK constraints yet, it > doesn't make any sense to me for it to allow function calls, since functions > can perform queries. Additionally, if a function is called from a check

[BUGS] BUG #6612: Functions can be called inside CHECK statements

2012-04-25 Thread atrigent
The following bug has been logged on the website: Bug reference: 6612 Logged by: Ari Entlich Email address: atrig...@ccs.neu.edu PostgreSQL version: 9.1.2 Operating system: Windows? Description: Seeing as Postgres does not allow sub-queries in CHECK constraints yet, i