pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Sam Barnett-Cormack <s.barnett-cormack@lancaster.ac.uk>
To: Gaetano Mendola <mendola@bigfoot.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: cast not IMMUTABLE?
Date: Fri, 7 May 2004 01:33:58 +0100 (BST)
Message-ID: <Pine.LNX.4.58.0405070132450.4035@localhost.localdomain> (raw)
In-Reply-To: <c7ei84$j0e$1@floppy.pyrenet.fr>
References: <c7ei84$j0e$1@floppy.pyrenet.fr>

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



view thread (7+ messages)  latest in thread

Message-ID: <Pine.LNX.4.58.0405070132450.4035@localhost.localdomain>
Permalink:  ../Pine.LNX.4.58.0405070132450.4035@localhost.localdomain/
Also on:    postgresql.org/message-id/Pine.LNX.4.58.0405070132450.4035@localhost.localdomain

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: s.barnett-cormack@lancaster.ac.uk, mendola@bigfoot.com
  Subject: Re: cast not IMMUTABLE?
  In-Reply-To: <Pine.LNX.4.58.0405070132450.4035@localhost.localdomain>
  References: <c7ei84$j0e$1@floppy.pyrenet.fr> <Pine.LNX.4.58.0405070132450.4035@localhost.localdomain>

* 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