Re: index on to_char(created, 'YYYY') doesn't work - Mailing list pgsql-sql

From Andreas Joseph Krogh
Subject Re: index on to_char(created, 'YYYY') doesn't work
Date
Msg-id 200301151152.05952.andreak@officenet.no
Whole thread Raw
In response to index on to_char(created, 'YYYY') doesn't work  (Andreas Joseph Krogh <andreak@officenet.no>)
Responses Re: index on to_char(created, 'YYYY') doesn't work  (Achilleus Mantzios <achill@matrix.gatewaynet.com>)
List pgsql-sql
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wednesday 15 January 2003 11:37, you wrote:
> The following does not work:
>
> create index session_u_idx on session (to_char(created, 'YYYY'));
> ERROR:  parser: parse error at or near "'YYYY'" at character 57
>
> Can I make a function to do this and index using the result of that
> funtion? Do anyone have an example of such a function?

I tried the following function:
- -----------------------------------------------------------------
create function drus (timestamp) returns varchar AS'   DECLARE       str_created VARCHAR;       created ALIAS FOR $1;
BEGIN      str_created:= to_char(created, ''YYYY'');       RETURN str_created;   END; 
' LANGUAGE 'plpgsql';

create index session_u_idx on session (drus(created));
- -----------------------------------------------------------------
But it failes with:
ERROR:  DefineIndex: index function must be marked isImmutable

Now the question is how do I mark an index function isImmutable?

- --
Andreas Joseph Krogh <andreak@officenet.no>There will always be someone who agrees with youbut is, inexplicably, a
moron.

gpg public_key: http://dev.officenet.no/~andreak/public_key.asc
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE+JUtlUopImDh2gfQRAl1XAKCkEDKxRDys/Di1gLLRDx6h0TGiPwCeI4FN
DNdajyaQTd27f8MeaWZ+xUE=
=T3we
-----END PGP SIGNATURE-----



pgsql-sql by date:

Previous
From: Andreas Joseph Krogh
Date:
Subject: index on to_char(created, 'YYYY') doesn't work
Next
From: Achilleus Mantzios
Date:
Subject: Re: index on to_char(created, 'YYYY') doesn't work