Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 08F83476699 for ; Wed, 15 Jan 2003 14:04:10 -0500 (EST) Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) by postgresql.org (Postfix) with ESMTP id B1FD5477151 for ; Wed, 15 Jan 2003 13:15:53 -0500 (EST) Received: from [63.195.55.98] (account ) by davinci.ethosmedia.com (CommuniGate Pro WebUser 4.0.2) with HTTP id 2314974; Wed, 15 Jan 2003 10:15:55 -0800 From: "Josh Berkus" Subject: Re: index on to_char(created, 'YYYY') doesn't work To: Steve Crawford , Andreas Joseph Krogh , Achilleus Mantzios Cc: pgsql-sql@postgresql.org X-Mailer: CommuniGate Pro Web Mailer v.4.0.2 Date: Wed, 15 Jan 2003 10:15:55 -0800 Message-ID: In-Reply-To: <20030115171944.13CE5103E0@polaris.pinpointresearch.com> MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/225 X-Sequence-Number: 11090 Steve, > BTW, I tried to create an index on the to_char function and had no > luck - > seems like it should work but it doesn't on 7.2.3 or 7.3.1. That's because functional indexes can't take any arguments other than column names. Therefore you'd need to: CREATE FUNCTION to_year (timestamp) RETURNS varchar AS 'SELECT to_char($1, ''YYYY'');' LANGUAGE 'sql' WITH (ISCACHABLE, ISSTRICT) (above is 7.2.3 syntax) Then use the to_year function in place of to_char for creating your index. -Josh Berkus