pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: nickf@ontko.com
Cc: PGSQL-SQL <pgsql-sql@postgresql.org>
Subject: Re: creating an index on a function
Date: Fri, 15 Feb 2002 11:00:11 -0500
Message-ID: <14110.1013788811@sss.pgh.pa.us> (raw)
In-Reply-To: <NEBBLAAHGLEEPCGOBHDGIELDEFAA.nickf@ontko.com>
References: <NEBBLAAHGLEEPCGOBHDGIELDEFAA.nickf@ontko.com>

"Nick Fankhauser" <nickf@ontko.com> writes:
> staging=# create index event_day on
> event(date_trunc('day',event_date_time));
> ERROR:  parser: parse error at or near "'"

You missed the fine print that says the function must be applied to
table column name(s) only.  No constants, no expressions.

You can get around this limitation by defining a custom function that
fills in whatever extra baggage you need.

My own first thought was that you could just use conversion to type
date, but that falls down.  Not for syntax reasons though:

regression=# create table foo (event_date_time timestamp);
CREATE
regression=# create index event_day on foo (date(event_date_time));
ERROR:  DefineIndex: index function must be marked iscachable

This raises a subtle point that you'd better think about before you go
too far in this direction: truncating a timestamp to date is not a very
well-defined operation, because it depends on the timezone setting.
Indexes on functions whose values might vary depend on who's executing
them are a recipe for disaster --- the index is almost certainly going
to wind up corrupted (out of order).

			regards, tom lane



view thread (4+ messages)  latest in thread

Message-ID: <14110.1013788811@sss.pgh.pa.us>
Permalink:  ../14110.1013788811@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/14110.1013788811@sss.pgh.pa.us

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, nickf@ontko.com
  Subject: Re: creating an index on a function
  In-Reply-To: <14110.1013788811@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