Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 815EB9FA49D for ; Mon, 11 Dec 2006 12:45:12 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 94503-01 for ; Mon, 11 Dec 2006 12:45:00 -0400 (AST) X-Greylist: delayed 00:24:53.853548 by SQLgrey-1.7.4 Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id C9EE59FA28E for ; Mon, 11 Dec 2006 12:45:00 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from mx.inode.at (lb01nat10.inode.at [62.99.145.10]) by svr4.postgresql.org (Postfix) with ESMTP id 2F08D5AF88F for ; Mon, 11 Dec 2006 16:20:24 +0000 (GMT) Received: from [83.64.182.18] (port=5701 helo=panettone.apus.local) by smartmx-10.inode.at with esmtp (Exim 4.50) id 1Gtnsm-0003ZU-KH for pgsql-performance@postgresql.org; Mon, 11 Dec 2006 17:20:00 +0100 Received: from xjens.apus.local ([193.1.1.148]) by panettone.apus.local with esmtp (Exim 3.35 #1 (Debian)) id 1Gtnsm-0000MN-00 for ; Mon, 11 Dec 2006 17:20:00 +0100 Date: Mon, 11 Dec 2006 17:19:27 +0100 To: pgsql-performance@postgresql.org Subject: really quick multiple inserts can use COPY? From: "Jens Schipkowski" Organization: APUS Software GmbH Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8 MIME-Version: 1.0 Content-Transfer-Encoding: Quoted-Printable Message-ID: User-Agent: Opera Mail/9.02 (Linux) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.186 tagged_above=0 required=5 tests=AWL, BAYES_50, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200612/242 X-Sequence-Number: 22298 Hello! In our JAVA application we do multiple inserts to a table by data from a= = Hash Map. Due to poor database access implemention - done by another = company (we got the job to enhance the software) - we cannot use prepare= d = statements. (We are not allowed to change code at database access!) First, we tried to fire one INSERT statement per record to insert. This = = costs 3 ms per row which is to slow because normally we insert 10.000 = records which results in 30.000 ms just for inserts. for(){ sql =3D "INSERT INTO tblfoo(foo,bar) VALUES("+it.next()+","+CONST.BAR+")= ;"; } I was searching for an quicker way - MSSQL offers Array Inserts - at = PostgreSQL. The only solution seem to be "INSERT INTO foo SELECT" and th= is = is really dirty. I improved the inserts using the subselect with union. sql =3D "INSERT INTO tblfoo(foo,bar) "; for(){ sql +=3D "SELECT "+it.next()+","+CONST.BAR+" UNION " ... } This results in a really long INSERT INTO SELECT UNION statement and wor= ks = correct and quick but looks dirty. When I heard about COPY I thought this will be the right way. But it doe= s = not work using JDBC. Testing via psql does it perfect but sending the sa= me = SQL statements via JDBC throws an error. -> BEGIN sql =3D "COPY tblfoo(foo,bar) FROM STDIN;\n1 'foobar'\n2 'foobar'\n\\.= "; -> COMMIT ERROR: syntax error at or near "1" at character 34 So, my questions: Is it possible to use COPY FROM STDIN with JDBC? Will it bring performance improvement compared to SELECT UNION solution?= many thanks in advance, Jens Schipkowski -- = ** APUS Software GmbH