Skip site navigation (1) Skip section navigation (2)

Re: cast not IMMUTABLE?

From: Sam Barnett-Cormack <s(dot)barnett-cormack(at)lancaster(dot)ac(dot)uk>
To: Gaetano Mendola <mendola(at)bigfoot(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: cast not IMMUTABLE?
Date: 2004-05-07 00:33:58
Message-ID: Pine.LNX.4.58.0405070132450.4035@localhost.localdomain (view raw or flat)
Thread:
Lists: pgsql-adminpgsql-hackers
On Fri, 7 May 2004, Gaetano Mendola wrote:

> Hi all,
> I have a table with ~ 3e+6 rows on it.
>
> I do select on this table in this way:
>
>
> (1) select * from user_logs where login_time::date = now()::date;
>
>
> consider that login_time is a TIMESTAMPTZ with an index on it.
>
> If I use the select in this way:
>
> select * from user_logs where login_time = now();
>
> the the index is used.
>
> I'm trying to use define and index in order to help the query (1):
>
>
> test# create index idx on user_logs ( (login_time::date) );
> ERROR:  functions in index expression must be marked IMMUTABLE
>
>
> why that cast is not considered IMMUTABLE ?
>
>
> How can I define an index for the query (1) ?

The way I have done such queries hs been to create functions, marked
immutable, that encapsulate the cast/non-immutable internal function, if
I know that it *is* really immutable, at least for my purposes, and use
a functional index.

-- 
Sam Barnett-Cormack
Software Developer                           |  Student of Physics & Maths
UK Mirror Service (http://www.mirror.ac.uk)  |  Lancaster University

In response to

pgsql-hackers by date

Next:From: Ismail KizirDate: 2004-05-07 00:38:52
Subject: Fw: Fixing the Turkish problem
Previous:From: Alvaro HerreraDate: 2004-05-06 23:59:56
Subject: Re: COPY command - CSV files

pgsql-admin by date

Next:From: Tom LaneDate: 2004-05-07 00:41:54
Subject: Re: cast not IMMUTABLE?
Previous:From: Gaetano MendolaDate: 2004-05-06 23:37:29
Subject: cast not IMMUTABLE?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group