pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ravi Krishna <srkrishna@fastmail.com>
To: pgsql-general <pgsql-general@lists.postgresql.org>
Subject: date_trunc not immutable
Date: Sat, 15 Dec 2018 18:26:24 -0500
Message-ID: <1544916384.3079614.1610261080.7F8C1B97@webmail.messagingengine.com> (raw)

Version: PG 10.6 on AWS Linux.

I am trying to create an index on function date_trunc('month',timestamp)
PG is complaining that the function must be marked as IMMUTABLE.  So I
assume that date_trunc is not marked as immutable.
Definition of immutable from PG documentation
====================================

All functions and operators used in an index definition must be
"immutable", that is, their results must depend only on their arguments
and never on any outside influence (such as the contents of another
table or the current time). This restriction ensures that the behavior
of the index is well-defined. To use a user-defined function in an index
expression or WHERE clause, remember to mark the function immutable when
you create it.===================================
What am I missing?  date_trunc will always return the same value for a
given value. Not sure how I can mark a PG function as immutable.

view thread (5+ messages)  latest in thread

Message-ID: <1544916384.3079614.1610261080.7F8C1B97@webmail.messagingengine.com>
Permalink:  ../1544916384.3079614.1610261080.7F8C1B97@webmail.messagingengine.com/
Also on:    postgresql.org/message-id/1544916384.3079614.1610261080.7F8C1B97@webmail.messagingengine.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: srkrishna@fastmail.com
  Subject: Re: date_trunc not immutable
  In-Reply-To: <1544916384.3079614.1610261080.7F8C1B97@webmail.messagingengine.com>
  References: <1544916384.3079614.1610261080.7F8C1B97@webmail.messagingengine.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox