From: Tom Lane <tgl@sss.pgh.pa.us>
To: Mark Steben <mark.steben@drivedominion.com>
Cc: pgsql-admin <pgsql-admin@postgresql.org>
Subject: Re: creating index with a cast statement in the predicate
Date: Mon, 31 Jul 2017 14:12:13 -0400
Message-ID: <7027.1501524733@sss.pgh.pa.us> (raw)
In-Reply-To: <CADyzmyxcrg-U2TECTDyj9gk=c21RwMpJf2HGk+fM3m3-bOyiZQ@mail.gmail.com>
References: <CADyzmyxcrg-U2TECTDyj9gk=c21RwMpJf2HGk+fM3m3-bOyiZQ@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-admin>
Mark Steben <mark.steben@drivedominion.com> writes:
> I would like to create an index on a column named value: defined as
> varchar(255)
> Values in this column can be many, including both dates and non-dates.
> The developers run a query that first uses a regular expression to filter
> non-dates out
> then, ANDS it with the following
> *and cast(value as date) >= date_trunc('MONTH', current_date) - interval '
> 2 Month '*
> When I attempt to create an index using this statement in the
> predicate, I get the error that states that functions in an index predicate
> must be marked as Immutable.
I think it's unhappy about the varchar-to-date cast. That is not
considered immutable because the behavior of date_in() depends on
the setting of DateStyle.
regards, tom lane
--
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
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 using the --to and --cc options:
reply via email
To: pgsql-admin@postgresql.org
Cc: tgl@sss.pgh.pa.us, mark.steben@drivedominion.com
Subject: Re: creating index with a cast statement in the predicate
In-Reply-To: <7027.1501524733@sss.pgh.pa.us>
* 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