Re: Creating a function index

From: "Henshall, Stuart - WCP" <SHenshall(at)westcountrypublications(dot)co(dot)uk>
To: 'Michael Labhard' <ince(at)pacifier(dot)com>, pgsql-cygwin(at)postgresql(dot)org
Subject: Re: Creating a function index
Date: 2002-08-30 15:15:33
Message-ID: E2870D8CE1CCD311BAF50008C71EDE8E01F74995@MAIL_EXCHANGE
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-cygwin

I was under the impression that you couldn't include
anything but columns in a function call for indexing
so you'd have to do something like the following (untested):
CREATE FUNCTION trunc_to_day(date) RETURNS timestamp AS '
DECLARE
y ALIAS FOR $1;
dt timestamp;
BEGIN
dt=date_trunc('day',y);
RETURN dt;
END;
' LANGUAGE 'plpgsql' WITH (isstrict,iscachable);

CREATE INDEX indx1 ON A (trunc_to_day(y));

Also I thought dates could dates so a truncation to
day surely wouldn't mean much
hth,
- Stuart

> -----Original Message-----
> From: Michael Labhard [mailto:ince(at)pacifier(dot)com]
> Sent: 30 August 2002 15:45
> To: pgsql-cygwin(at)postgresql(dot)org
> Subject: [CYGWIN] Creating a function index
>
>
> Apparantly creating a function index does not work if there
> is a single
> quote in the function expression? Example:
>
>
>
> CREATE TABLE A (
> x INTEGER
> , y DATE
> )
> ;
>
> INSERT INTO A VALUES( 1, CURRENT_DATE );
> INSERT INTO A VALUES( 2, CURRENT_DATE );
> INSERT INTO A VALUES( 3, CURRENT_DATE );
> INSERT INTO A VALUES( 4, CURRENT_DATE - CAST('1 day' AS INTERVAL) );
> --INSERT INTO A VALUES( 4, CURRENT_DATE - CAST('2 day' AS INTERVAL) );
> --INSERT INTO A VALUES( 4, CURRENT_DATE - CAST('3 day' AS INTERVAL) );
>
> CREATE INDEX indx1 ON A( DATE_TRUNC('day', y) );
>
> SELECT * FROM A WHERE y < CURRENT_DATE;
>
> DROP INDEX indx1;
> DROP TABLE A;
>
>
> Please advise. Thanks.
>
> -- Michael
>
>
>
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
>

Browse pgsql-cygwin by date

  From Date Subject
Next Message Tom Berger 2002-08-30 15:16:08 Problem with install instructions
Previous Message Michael Labhard 2002-08-30 14:45:06 Creating a function index