From: | Mark Steben <mark(dot)steben(at)drivedominion(dot)com> |
---|---|
To: | pgsql-admin <pgsql-admin(at)postgresql(dot)org> |
Subject: | creating index with a cast statement in the predicate |
Date: | 2017-07-31 17:33:43 |
Message-ID: | CADyzmyxcrg-U2TECTDyj9gk=c21RwMpJf2HGk+fM3m3-bOyiZQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin |
Good afternoon
I am currently running postgres 9.4.8.
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.
Our internal functions date_trunc (all 3) and date are all already defined
as immutable.
I can create an index with the regular expression as the predicate but not
the cast statement comparison.
Here is the regular expression index I constructed:
"primets_custattr_small_regexp" btree (value) WHERE value::text ~
'([0-9][0-9][0-9][0-9])-(0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01])|([0-9][0-9][0-9][0-9])-(0[469]|11])-(0[1-9]|[12][0-9]|30)|([0-9][0-9][0248][048]|[0-9][0-9][13579][26])-(02)-(0[1-9]|1[0-9]|2[0-9])|([0-9][0-9][0248][1235679]|[0-9][0-9][13579][01345789])-(02)-(0[1-9]|1[0-9]|2[0-8])'::text
I would appreciate any insight here. Thank you
--
*Mark Steben*
Database Administrator
@utoRevenue <http://www.autorevenue.com/> | Autobase
<http://www.autobase.net/>
CRM division of Dominion Dealer Solutions
95D Ashley Ave.
West Springfield, MA 01089
t: 413.327-3045
f: 413.383-9567
www.fb.com/DominionDealerSolutions
www.twitter.com/DominionDealer
www.drivedominion.com <http://www.autorevenue.com/>
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2017-07-31 18:12:13 | Re: creating index with a cast statement in the predicate |
Previous Message | Scott Whitney | 2017-07-28 22:19:40 | Re: pgdg96 repo with centos 7.x - server starts only on loopback |