Re: index on to_char(created, 'YYYY') doesn't work

From: Achilleus Mantzios <achill(at)matrix(dot)gatewaynet(dot)com>
To: Andreas Joseph Krogh <andreak(at)officenet(dot)no>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: index on to_char(created, 'YYYY') doesn't work
Date: 2003-01-15 16:12:15
Message-ID: Pine.LNX.4.44.0301151411490.2448-100000@matrix.gatewaynet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, 15 Jan 2003, Andreas Joseph Krogh wrote:

> -----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';

add
WITH (iscachable)

>
> 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(at)officenet(dot)no>
> There will always be someone who agrees with you
> but 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-----
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>

==================================================================
Achilleus Mantzios
S/W Engineer
IT dept
Dynacom Tankers Mngmt
Nikis 4, Glyfada
Athens 16610
Greece
tel: +30-10-8981112
fax: +30-10-8981877
email: achill(at)matrix(dot)gatewaynet(dot)com
mantzios(at)softlab(dot)ece(dot)ntua(dot)gr

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Josh Berkus 2003-01-15 17:17:28 Re: Performance of request of type WHERE ... IN ( ... )
Previous Message Tom Lane 2003-01-15 15:57:18 Re: index on to_char(created, 'YYYY') doesn't work