Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id D5EDAB5DC1B for ; Fri, 23 Sep 2011 15:46:13 -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 62653-02 for ; Fri, 23 Sep 2011 18:46:07 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from mail-fx0-f46.google.com (mail-fx0-f46.google.com [209.85.161.46]) by mail.postgresql.org (Postfix) with ESMTP id 1F534B5DBE0 for ; Fri, 23 Sep 2011 15:46:06 -0300 (ADT) Received: by fxe4 with SMTP id 4so4083879fxe.19 for ; Fri, 23 Sep 2011 11:46:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=1EZmHfJcw2xsmwsbveMqUcna8l1tAsePRXU0azmKabg=; b=lt1WueHI5OOooMc4YL79/JqPlCm/HPXJKvyPEs9a9nXBU8d0N5UtMq90x4bubajTTX VXEW40dISg1LUqZq3YrFRgII8ieGRKGpL8bC1LPJVlXTiJR7L8+tm5C/iQqcRAS+lnsU 55T3RUK1fBqHj4bz24qQOsQ5/SbawW64qldqo= Received: by 10.223.47.216 with SMTP id o24mr5452058faf.145.1316803566133; Fri, 23 Sep 2011 11:46:06 -0700 (PDT) Received: from [94.21.150.220] (94-21-150-220.pool.digikabel.hu. [94.21.150.220]) by mx.google.com with ESMTPS id l9sm11933157faa.26.2011.09.23.11.46.05 (version=SSLv3 cipher=OTHER); Fri, 23 Sep 2011 11:46:05 -0700 (PDT) Message-ID: <4E7CD3EC.2060407@gmail.com> Date: Fri, 23 Sep 2011 20:46:04 +0200 From: Bodor Andras User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.16) Gecko/20101123 SeaMonkey/2.0.11 MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: Re: Prepared statement with function as argument: how to bind values? References: <4E4ADB2A.5040902@gmail.com> <4E53FE39.40501@gmail.com> <4E6FA3DA.5090805@gmail.com> <4E77155D.8050200@gmail.com> <4E7753F7.9090903@gmail.com> <4E7CD2FB.6060808@gmail.com> In-Reply-To: <4E7CD2FB.6060808@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.789 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_ENVFROM_END_DIGIT=0.1, FREEMAIL_FROM=0.001, T_TO_NO_BRKTS_FREEMAIL=0.01 X-Spam-Level: X-Archive-Number: 201109/102 X-Sequence-Number: 22220 You may try this: INSERT INTO poi(geom,latitude,longitude,description,comment) VALUES (ST_GeomFromText('POINT(' || ? || ' ' || ? || ')', 4326), ?, ?, ?, ?); then you have 6 parameters to bind. Andras > Hi all, > > in my app I need to execute insert query one of the arguments of which > is a PostGIS > function call. Here is query > > INSERT INTO poi(geom,latitude,longitude,description,comment) > VALUES (ST_GeomFromText('POINT(34.567 45.5621)', 4326), 34.567, > 45.5621, 'some description', 'user comment'); > > The problem is that I can't bind all necessary values, I can't write > query as > > INSERT INTO poi(geom,latitude,longitude,description,comment) > VALUES (ST_GeomFromText('POINT(? ?)', 4326), ?, ?, ?, ?); > > and bind all values because in this case I get exception > > org.postgresql.util.PSQLException: The column index is out of range: > 6, number of columns: 5. > > How I can bind values for function arguments? I see two possible > solutions: > 1. create query string in runtime, concatenate all function arguments > and then bind all other values > 2. write stored fuction in database which will accept all arguments > and the internally call ST_GeomFromText > > In first case I can't prepare statement for multiple inserts and need > to create query string on every > insert operation. The secon approach looks a more flexible. > > Any hints on this problem? Maybe I miss something in documentation and > it is possible to bind values > to the functions arguments inside insert query? > > Thanks, > Alex >