Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ftAUv-0002hf-4r for pgsql-general@arkaria.postgresql.org; Fri, 24 Aug 2018 11:43:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ftAUt-000265-4s for pgsql-general@arkaria.postgresql.org; Fri, 24 Aug 2018 11:43:23 +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.89) (envelope-from ) id 1ftAUs-00025x-Pr for pgsql-general@lists.postgresql.org; Fri, 24 Aug 2018 11:43:22 +0000 Received: from mout.kundenserver.de ([212.227.126.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ftAUp-0004wL-Lc for pgsql-general@lists.postgresql.org; Fri, 24 Aug 2018 11:43:21 +0000 Received: from [10.8.0.146] ([185.40.248.10]) by mrelayeu.kundenserver.de (mreue004 [212.227.15.129]) with ESMTPSA (Nemesis) id 0M0v6Z-1g6Q7n0HhX-00v4Bf for ; Fri, 24 Aug 2018 13:43:16 +0200 Newsgroups: gmane.comp.db.postgresql.general X-Mozilla-News-Host: news://news.gmane.org:119 To: pgsql-general@lists.postgresql.org From: Thomas Kellerer Subject: Arrays, casting and "constrained" data types Message-ID: <693a9f48-07ce-ce8b-d4e6-c890b36aadcf@gmx.net> Date: Fri, 24 Aug 2018 13:43:15 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K1:CSYGshRVQxGUuCvYHzc8Z9MLg/EN/bv5Sm8XXzqACBkc5JPaRiz N/uba6qtjlCAWN+oEiRTQjtVqfG09yspXDnUgwse/2e1yarOM6x8yXWVBjTJWH6m14xGCA4 CZPMdCnFb93BGbJrUhT9urpL+FaMYJayM/oveOHEgDwUWACI4q16M/8EVbkR3CGS018qe17 kT8RJyUaZzgk3R4pthcFA== X-UI-Out-Filterresults: notjunk:1;V01:K0:6HLPU7uPJ6A=:uZpjcMIR0AsgBI019xeKR4 VeoAg9AQs6rKRXQ2z49tJeKOq/NfTrWm47O2L0/eEgyTt7nm84ePnbbe9YbxymLzAUgv79439 Mpt8Byu03u25YbZ0h8RmXwiHFMoI3a+Js4QCf/U/HsXS6rDlFzqQSIBNaHur21TDxIYkIHfRQ RgY8EekEn12btel+nmZDS6vxOye4/FgKG+JLJJNshtrnUiXaCboIkLoVgEanyLyVaxHE9HKt9 DVxmNw7RWklsXPIPk94TW0WlNcLlf0qqTtDp+9ZCMcp+GDIyhyJsQtV+ZP5BjiMJnqx4oK4rd 4Inepwtt7tJ9En3DSwH4aa843RRE8rG2la7oUpYhVzkHdytpY0Y9lvu2e4nTSQMXHTHPcgTxP KaLcvHBk27SmpRMlwbuwXKz2pDEK0wv1PM4U6jt+OMPSFErkvDy+GvCgJTBNGj/yCq5ddz2pr L0EMJR19gCyCCXM939OQiVgN9GTFE8NkRSPyGmukoUkoICJ1iSkBky2gnzJEuD1EFdt9SQ6gc WTqgsBun3yMpS4a9Tu5hOvlM1X3nmyr/sCa7eu6M2ByZRQOgACxAslTzIgtto6iPnDNpak03U 4u1luGxYr548qUyuHQ6VRhTA3AwG6vwe/c/OQC1HR6VSZrOnz0EbGzNwqjty6hYwOqo3AhL1Y 2nAYHS5VS8t1YXYJi4tQPWCxkJZ/bBOPpD1aZRzsjkm09vrK6jMb252ipF16NcAOFLOb1YNqT YiwYMiBhx7ks0Z3t List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I stumbled across the following: Consider the following (simplified) table: create table test ( val numeric(20,0), ref_val numeric(20,0) ); and the following very simple recursive CTE: with recursive tree as ( select val, array[val] as path from test union all select child.val, parent.path||child.val from test child join tree parent on parent.val = child.ref_val ) select * from tree; The above fails with: recursive query "tree" column 2 has type numeric(20,0)[] in non-recursive term but type numeric[] overall However, when casting the array in the non-recursive part, it still doesn't work: with recursive tree as ( select val, array[val]::numeric[] as path from test union all select child.val, parent.path||child.val from test child join tree parent on parent.val = child.ref_val ) select * from tree; same error as before. Neither does array[val::numeric] work. However, appending the column to an empty array works: with recursive tree as ( select val, array[]::numeric[] || val as path from test union all select child.val, parent.path||child.val from test child join tree parent on parent.val = child.ref_val ) select * from tree; My question is: why isn't "array[val]::numeric[]" enough to create a numeric[] array in the non-recursive part? I have seen the same problem with "varchar(x)" Thomas