Re: [GENERAL] ERROR: functions in index expression must be markedIMMUTABLE - Mailing list pgsql-general

From Adrian Klaver
Subject Re: [GENERAL] ERROR: functions in index expression must be markedIMMUTABLE
Date
Msg-id 5e3ef9d4-de24-4830-0ca1-37c29f320df2@aklaver.com
Whole thread Raw
In response to Re: [GENERAL] ERROR: functions in index expression must be markedIMMUTABLE  ("Sven R. Kunze" <srkunze@mail.de>)
Responses Re: [GENERAL] ERROR: functions in index expression must be marked IMMUTABLE  ("David G. Johnston" <david.g.johnston@gmail.com>)
Re: [GENERAL] ERROR: functions in index expression must be marked IMMUTABLE  (Geoff Winkless <pgsqladmin@geoff.dj>)
List 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:


https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/backend/utils/adt/formatting.c;h=e552c8d20b61a082049068d2f8d776e35fef1179;hb=HEAD

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.klaver@aklaver.com


pgsql-general by date:

Previous
From: Jon Nelson
Date:
Subject: Re: [GENERAL] Shared WAL archive between master and standby: WALs notalways identical
Next
From: Steve Crawford
Date:
Subject: Re: [GENERAL] GMT FATAL: remaining connection slots are reserved fornon-replication superuser connections, but I'm using pgBouncer for connection pooling