From: | Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> |
---|---|
To: | "Sven R(dot) Kunze" <srkunze(at)mail(dot)de>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: ERROR: functions in index expression must be marked IMMUTABLE |
Date: | 2017-02-28 15:59:07 |
Message-ID: | 5e3ef9d4-de24-4830-0ca1-37c29f320df2@aklaver.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 02/28/2017 07:30 AM, Sven R. Kunze wrote:
> On 28.02.2017 15:40, Adrian Klaver wrote:
>> [explanation of why date casting and to_datetime don't work]
>
> Why is to_date not immutable?
Not sure, but if I where to hazard a guess, from the source code in
formatting.c:
to_date(PG_FUNCTION_ARGS)
{
text *date_txt = PG_GETARG_TEXT_P(0);
text *fmt = PG_GETARG_TEXT_P(1);
DateADT result;
struct pg_tm tm;
fsec_t fsec;
do_to_timestamp(date_txt, fmt, &tm, &fsec);
....
/*
* do_to_timestamp: shared code for to_timestamp and to_date
The shared code makes it not immutable:
test=> select * from pg_proc where proname ilike 'to_date';
...
provolatile | s
....
https://www.postgresql.org/docs/9.6/static/catalog-pg-proc.html
provolatile char
provolatile tells whether the function's result depends only on its
input arguments, or is affected by outside factors. It is i for
"immutable" functions, which always deliver the same result for the same
inputs. It is s for "stable" functions, whose results (for fixed inputs)
do not change within a scan. It is v for "volatile" functions, whose
results might change at any time. (Use v also for functions with
side-effects, so that calls to them cannot get optimized away.)
>
> Regards,
> Sven
>
>
>
--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Steve Crawford | 2017-02-28 16:06:33 | Re: GMT FATAL: remaining connection slots are reserved for non-replication superuser connections, but I'm using pgBouncer for connection pooling |
Previous Message | Jon Nelson | 2017-02-28 15:57:14 | Re: Shared WAL archive between master and standby: WALs not always identical |