pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Brent Verner <brent@rcfile.org>
To: Nick Fankhauser <nickf@ontko.com>
Cc: PGSQL-SQL <pgsql-sql@postgresql.org>
Subject: Re: creating an index on a function
Date: Fri, 15 Feb 2002 10:42:52 -0500
Message-ID: <20020215154252.GA78209@rcfile.org> (raw)
In-Reply-To: <NEBBLAAHGLEEPCGOBHDGIELDEFAA.nickf@ontko.com>
References: <NEBBLAAHGLEEPCGOBHDGIELDEFAA.nickf@ontko.com>

[2002-02-15 09:26] Nick Fankhauser said:
| Good Morning everyone!
| 
| I just tried to create an index on a function with no success. My syntax
| seems to match the syntax shown in the docs for Create Index, but I get an
| error. Any thoughts would be appreciated. Here is my attempt-
| 
| First, I did a select to make sure I had the function syntax correct, and
| then tried to create the index:
| 
| 
| staging=# select count(*) from event where
| date_trunc('day',event_date_time)='07/27/2001';
|  count
| -------
|     27
| (1 row)
| 
| staging=#
| staging=# create index event_day on
| event(date_trunc('day',event_date_time));

You cannot create an index on a function with constant parameters.
This limitation may be removed in a future version, but for now
you have to create a wrapper function that doesn't require the
constant parameter

  CREATE FUNCTION date_trunc_day(TIMESTAMP) RETURNS TIMESTAMP AS '
     SELECT date_trunc(''day'',$1);
  ' LANGUAGE 'sql';

then use this to create your function index.
  
   create index event_day on
     event(date_trunc_day(event_date_time));

hth.
  brent

-- 
"Develop your talent, man, and leave the world something. Records are 
really gifts from people. To think that an artist would love you enough
to share his music with anyone is a beautiful thing."  -- Duane Allman



view thread (4+ messages)  latest in thread

Message-ID: <20020215154252.GA78209@rcfile.org>
Permalink:  ../20020215154252.GA78209@rcfile.org/
Also on:    postgresql.org/message-id/20020215154252.GA78209@rcfile.org

 · 

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: brent@rcfile.org, nickf@ontko.com
  Subject: Re: creating an index on a function
  In-Reply-To: <20020215154252.GA78209@rcfile.org>

* 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