X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 6E5E832AD91 for ; Thu, 21 Oct 2004 07:19:04 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 80409-02 for ; Thu, 21 Oct 2004 06:18:59 +0000 (GMT) Received: from hosting.commandprompt.com (128.commandprompt.com [207.173.200.128]) by svr1.postgresql.org (Postfix) with ESMTP id DE07132A849 for ; Thu, 21 Oct 2004 07:18:59 +0100 (BST) Received: from [192.168.1.20] (clbb-248.saw.net [64.146.135.248]) (authenticated) by hosting.commandprompt.com (8.11.6/8.11.6) with ESMTP id i9L6FRD07936; Wed, 20 Oct 2004 23:15:27 -0700 Message-ID: <4177538C.7010900@commandprompt.com> Date: Wed, 20 Oct 2004 23:13:32 -0700 From: "Joshua D. Drake" Organization: Command Prompt, Inc. User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Lane Cc: Ray , pgsql-performance@postgresql.org Subject: Re: create index with substr function References: <069201c4b715$34851670$0f6010ac@raysiu> <10774.1098327554@sss.pgh.pa.us> In-Reply-To: <10774.1098327554@sss.pgh.pa.us> Content-Type: multipart/alternative; boundary="------------080507080403000504090501" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.0 tagged_above=0.0 required=5.0 tests=HTML_20_30, HTML_MESSAGE, HTML_TITLE_EMPTY X-Spam-Level: * X-Archive-Number: 200410/339 X-Sequence-Number: 8815 This is a multi-part message in MIME format. --------------080507080403000504090501 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Tom Lane wrote: >"Ray" writes: > > >>CREATE INDEX idx_doc_substr_doc_urn ON doc USING btree (SUBSTR(doc_urn,10)); >>ERROR: parser: parse error at or near "10" at character 68 >> >> > >This will work in 7.4, but not older releases. > > > Can't you just use a SQL function that calls the substr function? I have done that with date functions before like: CREATE OR REPLACE FUNCTION get_month(text) returns double precision AS ' SELECT date_part('month',$1); ' LANGUAGE 'SQL' IMMUTABLE; CREATE INDEX get_month_idx on foo(get_month(date_field)); Or in this case: CREATE OR REPLACE FUNCTION sub_text(text) returns text AS ' SELECT SUBSTR($1,10) from foo; ' LANGUAGE 'SQL' IMMUTABLE; CREATE INDEX sub_text_idx ON foo(sub_text(doc_urn)); This works on 7.3.6??? Sincerely, Joshua D. Drake > regards, tom lane > >---------------------------(end of broadcast)--------------------------- >TIP 7: don't forget to increase your free space map settings > > -- Command Prompt, Inc., home of Mammoth PostgreSQL - S/ODBC and S/JDBC Postgresql support, programming shared hosting and dedicated hosting. +1-503-667-4564 - jd@commandprompt.com - http://www.commandprompt.com PostgreSQL Replicator -- production quality replication for PostgreSQL --------------080507080403000504090501 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit Tom Lane wrote:
"Ray" <ray_siu@ge-ts.com.hk> writes:
  
CREATE INDEX idx_doc_substr_doc_urn ON doc USING btree (SUBSTR(doc_urn,10));
ERROR:  parser: parse error at or near "10" at character 68
    

This will work in 7.4, but not older releases.

  
Can't you just use a SQL function that calls the substr function? I have done that with date functions before
like:
CREATE OR REPLACE FUNCTION get_month(text) returns double precision AS '
   SELECT date_part('month',$1);
' LANGUAGE 'SQL' IMMUTABLE;

CREATE INDEX get_month_idx on foo(get_month(date_field));
Or in this case:

CREATE OR REPLACE FUNCTION sub_text(text) returns text AS '
      SELECT SUBSTR($1,10) from foo;
' LANGUAGE 'SQL' IMMUTABLE;

CREATE INDEX sub_text_idx ON foo(sub_text(doc_urn));

This works on 7.3.6???

Sincerely,

Joshua D. Drake




			regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings
  


-- 
Command Prompt, Inc., home of Mammoth PostgreSQL - S/ODBC and S/JDBC
Postgresql support, programming shared hosting and dedicated hosting.
+1-503-667-4564 - jd@commandprompt.com - http://www.commandprompt.com
PostgreSQL Replicator -- production quality replication for PostgreSQL
--------------080507080403000504090501--