Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id B66CCB5DBF0; Wed, 25 May 2011 08:29:41 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 17804-09; Wed, 25 May 2011 11:29:34 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from outmail149120.authsmtp.net (outmail149120.authsmtp.net [62.13.149.120]) by mail.postgresql.org (Postfix) with ESMTP id 19A5BB5DBE6; Wed, 25 May 2011 08:29:33 -0300 (ADT) Received: from mail-c193.authsmtp.com (mail-c193.authsmtp.com [62.13.128.118]) by punt6.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id p4PBTVin020081; Wed, 25 May 2011 12:29:31 +0100 (BST) Received: from [192.168.23.4] (212.100.42.202.fixip.bitel.net [212.100.42.202]) (authenticated bits=0) by mail.authsmtp.com (8.14.2/8.14.2) with ESMTP id p4PBTMPv008899; Wed, 25 May 2011 12:29:23 +0100 (BST) Message-ID: <4DDCE812.10401@2ndQuadrant.com> Date: Wed, 25 May 2011 13:29:22 +0200 From: Susanne Ebrecht User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110424 Thunderbird/3.1.10 MIME-Version: 1.0 To: Ingmar Brouns CC: pgsql-bugs@postgresql.org, pgsql-docs@postgresql.org Subject: Re: BUG #5926: information schema dtd_identifier for element_types, columns, parameters views inconsistent References: <201103111318.p2BDITcL034900@wwwmaster.postgresql.org> In-Reply-To: <201103111318.p2BDITcL034900@wwwmaster.postgresql.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Server-Quench: 3da31523-86c2-11e0-97bb-002264978518 X-AuthReport-Spam: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-AuthRoute: OCdxZQATClZOUR8T DCUJJHVGRTw4LxFW CBkfawBdJUwMSABN M15eIxoIcUtGGBZ8 Ui8UWVRVUU1wW2l3 YgBTbktfY0hQXgVq TkxLXFBSFhpqBAMB SF4aMmsWCmUAeH54 bU9rEHFYWEx/O0Up E01VEG8FeG9mO2IC UUENdx5dd1EYYx9F aFJ5UHoKaWAGbjQC El17DBoMEg5qYA5o bUlGcANIHxRDHzgy QAoHFCkuGktNXC4z IhkvYlIAEHEQPkg0 LVovWF8CexEVEEVT G0xIDSlFEEUQXycw SWESVkkaDThbWmMU GhQyKxpFHjFIQWJG BUZaUFkODShCVjJJ UypQVDFF X-Authentic-SMTP: 61633235383639.1014:706 X-AuthFastPath: 0 (Was 255) X-AuthVirus-Status: No virus detected - but ensure you scan with your own anti-virus system. X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201105/181 X-Sequence-Number: 30320 On 11.03.2011 14:18, Ingmar Brouns wrote: > The following bug has been logged online: > > Bug reference: 5926 > Logged by: Ingmar Brouns > Email address: swingi@gmail.com > PostgreSQL version: 9.0.3 > Operating system: Ubuntu 9.0.4 > Description: information schema dtd_identifier for element_types, > columns, parameters views inconsistent > Details: > > Hi, > > I am writing a function that needs to retrieve information with respect to > the types of parameters of functions. I use the information schema for that. > The parameters view documentation states: > > data_type: Data type of the parameter, if it is a built-in type, or ARRAY if > it is some array (in that case, see the view element_types) > > So for arrays I will have to join with information_schema.element_types > > http://www.postgresql.org/docs/9.0/static/infoschema-element-types.html > > At the top op that documentation is some example code, it joins on > dtd_identifier, the code does not work: > > create table public.test_table(a varchar array, b integer, c integer > array); > > SELECT c.column_name, c.data_type, e.data_type AS element_type > FROM information_schema.columns c > LEFT JOIN information_schema.element_types e > ON ((c.table_catalog, c.table_schema, c.table_name, 'TABLE', > c.dtd_identifier) > = (e.object_catalog, e.object_schema, e.object_name, e.object_type, > e.dtd_identifier)) > WHERE c.table_schema = 'public' AND c.table_name = 'test_table' > ORDER BY c.ordinal_position; > > column_name | data_type | element_type > -------------+-----------+-------------- > a | ARRAY | > b | integer | > c | ARRAY | > (3 rows) > > The same holds when joining with the parameters view. The reason seems to be > that the dtd_identifier of the element_types view has prepended 'a's whereas > the dtd_identifiers of the columns and parameter views do not: > > select column_name,dtd_identifier > from information_schema.columns c > where c.table_schema = 'public' > and c.table_name = 'test_table'; > > column_name | dtd_identifier > -------------+---------------- > a | 1 > b | 2 > c | 3 > (3 rows) > > select dtd_identifier > from information_schema.element_types e > where e.object_schema = 'public' > and e.object_name = 'test_table'; > > dtd_identifier > ---------------- > a1 > a3 > (2 rows) > > The element_types view has a column 'collection_type_identifier', this > column is not present in the documentation. It is defined exactly as the > dtd_identifier, only then without the prepended 'a': > > ('a'::text || x.objdtdid::text)::information_schema.sql_identifier AS > dtd_identifier > x.objdtdid ::information_schema.sql_identifier AS > collection_type_identifier > > When I modify the example code to join on this column instead, I get the > expected results: > > SELECT c.column_name, c.data_type, e.data_type AS element_type > FROM information_schema.columns c LEFT JOIN information_schema.element_types > e > ON ((c.table_catalog, c.table_schema, c.table_name, 'TABLE', > c.dtd_identifier) > = (e.object_catalog, e.object_schema, e.object_name, e.object_type, > e.collection_type_identifier)) > WHERE c.table_schema = 'public' AND c.table_name = 'test_table' > ORDER BY c.ordinal_position; > > column_name | data_type | element_type > -------------+-----------+------------------- > a | ARRAY | character varying > b | integer | > c | ARRAY | integer > (3 rows) > > Many thanks for figuring this out. I think we should fix the documentation here. Best Regards, Susanne Ebrecht -- Susanne Ebrecht - 2ndQuadrant PostgreSQL Development, 24x7 Support, Training and Services www.2ndQuadrant.com