pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Josh Berkus <josh@agliodbs.com>
To: Steve Crawford <scrawford@pinpointresearch.com>
To: Andreas Joseph Krogh <andreak@officenet.no>
To: Achilleus Mantzios <achill@matrix.gatewaynet.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: index on to_char(created, 'YYYY') doesn't work
Date: Wed, 15 Jan 2003 10:15:55 -0800
Message-ID: <web-2314974@davinci.ethosmedia.com> (raw)
In-Reply-To: <20030115171944.13CE5103E0@polaris.pinpointresearch.com>

Steve,

> BTW, I tried to create an index on the to_char function and had no
> luck - 
> seems like it should work but it doesn't on 7.2.3 or 7.3.1.

That's because functional indexes can't take any arguments other than
column names.   Therefore you'd need to:

CREATE FUNCTION to_year (timestamp) RETURNS varchar AS
'SELECT to_char($1, ''YYYY'');'
LANGUAGE 'sql' WITH (ISCACHABLE, ISSTRICT)
(above is 7.2.3 syntax)

Then use the to_year function in place of to_char for creating your
index.

-Josh Berkus



view thread (11+ messages)  latest in thread

Message-ID: <web-2314974@davinci.ethosmedia.com>
Permalink:  ../web-2314974@davinci.ethosmedia.com/
Also on:    postgresql.org/message-id/web-2314974@davinci.ethosmedia.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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: josh@agliodbs.com, scrawford@pinpointresearch.com, andreak@officenet.no, achill@matrix.gatewaynet.com
  Subject: Re: index on to_char(created, 'YYYY') doesn't work
  In-Reply-To: <web-2314974@davinci.ethosmedia.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