![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
Hi, A question on IMMUTABLE functions: do they only have to return the same value during a session/connection or during the databse server's lifetime? The documentation does not say anything about that. |
#2
| |||
| |||
|
|
A question on IMMUTABLE functions: do they only have to return the same value during a session/connection or during the databse server's lifetime? |
|
I wrote a function that uses the CURRENT_USER session variable, and for my current usage it is very important, that it returns a different value for each database connection. |
#3
| |||
| |||
|
|
On Fri, 5 Sep 2003, Daniel Schreiber wrote: Hi, A question on IMMUTABLE functions: do they only have to return the same value during a session/connection or during the databse server's lifetime? The documentation does not say anything about that. The function should always return the same value result the same inputs. I think you'll want to rewrite to take it as an argument (otherwise there might be uses that get converted to a constant where you want it to vary). This is the section in create function reference page about immutable. I'd thought it was clear, but do you have a better suggested wording? para literal>IMMUTABLE</literal> indicates that the function always returns the same result when given the same argument values; that is, it does not do database lookups or otherwise use information not directly present in its parameter list. If this option is given, any call of the function with all-constant arguments can be immediately replaced with the function value. /para |
#4
| |||
| |||
|
|
Okay, thanks for the help. I will rewrite the function as STABLE. Btw: is there documentation which parts in the environment are STABLE/IMMUTABLE? |
#5
| |||
| |||
|
|
This is the section in create function reference page about immutable. I'd thought it was clear, but do you have a better suggested wording? |
#6
| |||
| |||
|
|
While we're on the subject, this adjacent paragraph of the docs seems unclear: STABLE indicates that within a single table scan the function will consistently return the same result for the same argument values, but that its result could change across SQL statements. This is the appropriate selection for functions whose results depend on database lookups, parameter variables (such as the current time zone), etc. Also note that the current_timestamp family of functions qualify as stable, since their values do not change within a transaction. So, can a STABLE function change across SQL statements (as the beginning of the paragraph implies), or across transactions (as the end of the paragraph implies)? |
#7
| |||
| |||
|
|
-----Original Message----- From: pgsql-bugs-owner (AT) postgresql (DOT) org [mailto gsql-bugs-owner (AT) postgresql (DOT) org]On Behalf Of Neil ConwaySent: Friday, September 05, 2003 2:32 PM To: Stephan Szabo Cc: Daniel Schreiber; pgsql-bugs (AT) postgresql (DOT) org Subject: Re: [BUGS] Unclear documentation (IMMUTABLE functions) On Fri, 2003-09-05 at 10:01, Stephan Szabo wrote: This is the section in create function reference page about immutable. I'd thought it was clear, but do you have a better suggested wording? While we're on the subject, this adjacent paragraph of the docs seems unclear: STABLE indicates that within a single table scan the function will consistently return the same result for the same argument values, but that its result could change across SQL statements. This is the appropriate selection for functions whose results depend on database lookups, parameter variables (such as the current time zone), etc. Also note that the current_timestamp family of functions qualify as stable, since their values do not change within a transaction. So, can a STABLE function change across SQL statements (as the beginning of the paragraph implies), or across transactions (as the end of the paragraph implies)? -Neil ---------------------------(end of broadcast)--------------------------- TIP 6: Have you searched our list archives? http://archives.postgresql.org |
![]() |
| Thread Tools | |
| Display Modes | |
| |