Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cte1a-0005rn-VN for pgsql-hackers@arkaria.postgresql.org; Thu, 30 Mar 2017 17:38:19 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cte1a-0005IQ-FK for pgsql-hackers@arkaria.postgresql.org; Thu, 30 Mar 2017 17:38:18 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cte05-0002cj-Hz for pgsql-hackers@postgresql.org; Thu, 30 Mar 2017 17:36:45 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by makus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cte02-0001a4-Bv for pgsql-hackers@postgresql.org; Thu, 30 Mar 2017 17:36:44 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id C677321C23DE; Thu, 30 Mar 2017 20:36:39 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru Subject: Re: [PATCH] Generic type subscripting DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1490895399; bh=uy4+gwAQs7/ciY3lBbMF8orVcbiZmiRyeq/6idEybNw=; h=To:References:Cc:From:Date:In-Reply-To; b=S6ZWSFHfRU2AHALAifWUNiBPvwOeu1hb/y+3Bu9fWlhxHhcscxtP1oOJMZg+wlcOk fM6CxvHKBUEOQptWzwD57tKtNDjB72VGHeNNyuQg6YA4gxWd/MEUhpIrqKeb/z5Se7 FS7IrAQ6ZiylNgl9p8yTQMJdf0xKcH/PblixH95o= To: Dmitry Dolgov <9erthalion6@gmail.com> References: <20423.1489533013@sss.pgh.pa.us> <393cd0ae-5b84-849e-fc73-7077470a009e@pgmasters.net> <65df4a65-a9d8-3531-5baf-edb237771f0e@pgmasters.net> <22355.1490369372@sss.pgh.pa.us> <449f42b9-f338-9e45-cb33-3e15c7b547ad@postgrespro.ru> <38e32275-91f2-61e9-24dd-57135a662c41@postgrespro.ru> Cc: Tom Lane , David Steele , peter.eisentraut@2ndquadrant.com, PostgreSQL-development From: Arthur Zakirov Message-ID: <91a90c4e-9e95-60be-d796-d319b640655c@postgrespro.ru> Date: Thu, 30 Mar 2017 20:36:40 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <38e32275-91f2-61e9-24dd-57135a662c41@postgrespro.ru> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 29.03.2017 20:14, Arthur Zakirov wrote: > > I wanted to implement subscripting for ltree or hstore extensions. > Subscripting for ltree looks more interesting. Especially with slicing. > But I haven't done it yet. I hope that I will implement it tomorrow. > ltree ----- I've implemented fetching ltree elements using subscripting. But haven't implemented assigning ltree elements yet. I'll send second patch after implementing assigning. Now you can execute the following query: SELECT ('Top.Science.Astronomy.Astrophysics'::ltree)[1:2]; ltree ------------- Top.Science Comments -------- But I've noticed about some points. In array_subscript_parse() passed uninitialized values of "typesource" and "typeneeded" variables for coerce_to_target_type(). > + typesource = exprType(assignExpr); > + typesource = is_slice ? sbsref->refcontainertype : sbsref->refelemtype; Here is the bug. Second variable should be "typeneeded". Moreover these assignments should be moved up to first coerce_to_target_type() execution. > + foreach(l, sbsref->reflowerindexpr) > + { > + List *expr_ai = (List *) lfirst(l); > + A_Indices *ai = (A_Indices *) lfirst(list_tail(expr_ai)); > + > + subexpr = (Node *) lfirst(list_head(expr_ai)); This code looks like a magic. This happens because of appending A_Indeces to lowerIndexpr: > - subexpr = NULL; > + lowerIndexpr = lappend(lowerIndexpr, list_make2(subexpr, ai)); > } And this A_Indeces used only when slicing is not used to make a constant 1. Maybe there are another way? Also it would be better if "refevalfunc" and "refnestedfunc" had pointers to functions not Oid type. Now you need to create "..._fetch" and "..._assign" functions in catalog and in "..._parse" function you need get their Oid using to_regproc() function. Can we use IndexAmRoutine structure method, when you use only pointers to necessary functions? You can see an example in blhandler() function in blutils.c. The last point is about the tutorial. As Tom pointed it is not useful when the tutorial doesn't execute. It happens because there is not "custom" type in subscripting.sql. Also it contradicts the README of tutorials. -- Arthur Zakirov Postgres Professional: http://www.postgrespro.com Russian Postgres Company -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers