pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedcreating index with a cast statement in the predicate
2+ messages / 2 participants
[nested] [flat]
* creating index with a cast statement in the predicate
@ 2017-07-31 17:33 Mark Steben <mark.steben@drivedominion.com>
2017-07-31 18:12 ` Re: creating index with a cast statement in the predicate Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 2+ messages in thread
From: Mark Steben @ 2017-07-31 17:33 UTC (permalink / raw)
To: 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/;
<http://autobasedigital.net/marketing/DD12_sig.jpg;
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: creating index with a cast statement in the predicate
2017-07-31 17:33 creating index with a cast statement in the predicate Mark Steben <mark.steben@drivedominion.com>
@ 2017-07-31 18:12 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2017-07-31 18:12 UTC (permalink / raw)
To: Mark Steben <mark.steben@drivedominion.com>; +Cc: pgsql-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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2017-07-31 18:12 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-07-31 17:33 creating index with a cast statement in the predicate Mark Steben <mark.steben@drivedominion.com>
2017-07-31 18:12 ` Tom Lane <tgl@sss.pgh.pa.us>
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