Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 4B352632D8B for ; Sat, 7 Feb 2009 18:18:25 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 97280-10 for ; Sat, 7 Feb 2009 18:18:22 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.televork.ee (mail.televork.ee [81.21.241.190]) by mail.postgresql.org (Postfix) with ESMTP id F414D632C17 for ; Sat, 7 Feb 2009 18:18:21 -0400 (AST) Received: from localhost (localhost [127.0.0.1]) by mail.televork.ee (Postfix) with ESMTP id E7D7E17EAAF; Sun, 8 Feb 2009 00:18:23 +0200 (EET) X-Virus-Scanned: at mail.televork.ee Received: from mail.televork.ee ([81.21.241.190]) by localhost (mail.televork.ee [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id eSpgx+AMrXWF; Sun, 8 Feb 2009 00:18:16 +0200 (EET) Received: from [127.0.0.1] (81-21-242-98.televork.ee [81.21.242.98]) by mail.televork.ee (Postfix) with ESMTP id 66FAA95B1; Sun, 8 Feb 2009 00:18:13 +0200 (EET) Subject: Re: jdbc refuses to pass array argument using ARRAY[...] syntax From: Hannu Krosing To: Kris Jurka Cc: pgsql-jdbc@postgresql.org In-Reply-To: <1234043844.6818.1.camel@huvostro> References: <1234023235.9180.19.camel@huvostro> <1234043844.6818.1.camel@huvostro> Content-Type: text/plain Date: Sun, 08 Feb 2009 00:18:06 +0200 Message-Id: <1234045086.6818.34.camel@huvostro> Mime-Version: 1.0 X-Mailer: Evolution 2.24.3 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200902/20 X-Sequence-Number: 19295 On Sat, 2009-02-07 at 23:57 +0200, Hannu Krosing wrote: > On Sat, 2009-02-07 at 11:28 -0500, Kris Jurka wrote: > > > > On Sat, 7 Feb 2009, Hannu Krosing wrote: > > > > > org.postgresql.util.PSQLException: org.postgresql.util.PSQLException: > > > ERROR: array value must start with "{" or dimension information > > > > This is a server error message, not a JDBC driver message. > > > > > and yes, the full query string returned from myPrepared > > > Statement.toString() is valid SQL and does produce desired results when > > > I paste it in psql, so the problem is very likely overly paranoid checks > > > in PG jdbc driver. > > > > > > m3=# select * from mytypearrayfunc( 1, ARRAY[ > > > m3(# ROW(7,'{5,6,7}','{4}')::mytype, > > > m3(# ROW(2,'{2}','{3,4}')::mytype, > > > m3(# ROW(1,'{1}','{}')::mytype > > > m3(# ] ) > > > > Since you're using a prepared statement, this isn't the same thing. The > > equivalent is really: > > > > PREPARE myplan ( mytype[] ) AS SELECT * FROM > > mytypearraryfunc($1); > > > > EXECUTE myplan ( 'ARRAY[..]'::mytype[] ); > > > > ARRAY is a grammar construct and cannot be part of the parameter. > > weird, since this works too > > m3=# prepare myplan(mytype[]) as SELECT * FROM mytypearraryfunc(1,$1); > PREPARE > m3=# execute myplan(ARRAY[ > m3(# ROW(10, '{1,2,3}','{7,8,9}')::mytype, > m3(# ROW(11, '{1}','{3,4,5,6,7}')::mytype, > m3(# ROW(10, '{}','{7}')::mytype > m3(# ]); > status | file_id | delete_heirs | add_heirs > --------+---------+--------------+------------- > 200 | 10 | {1,2,3} | {7,8,9} > 200 | 11 | {1} | {3,4,5,6,7} > 200 | 10 | {} | {7} > (3 rows) > m3=# Oh, did not notice the '' around : so the right way to do it would be m3=# execute myplan(E'{"(10,\\"{1,2,3}\\",\\"{7,8,9}\\")","(11,{1},\ \\"{3,4,5,6,7}\\")","(10,{},{7})"}'::inheritance_change_type[]); status | file_id | delete_heirs | add_heirs --------+---------+--------------+------------- 200 | 10 | {1,2,3} | {7,8,9} 200 | 11 | {1} | {3,4,5,6,7} 200 | 10 | {} | {7} (3 rows) Thanks :) -- > ------------------------------------------ > Hannu Krosing http://www.2ndQuadrant.com > PostgreSQL Scalability and Availability > Services, Consulting and Training > > -- ------------------------------------------ Hannu Krosing http://www.2ndQuadrant.com PostgreSQL Scalability and Availability Services, Consulting and Training