From: Bodor Andras <bodri.mh3@gmail.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: Prepared statement with function as argument: how to bind values?
Date: Fri, 23 Sep 2011 20:46:04 +0200
Message-ID: <4E7CD3EC.2060407@gmail.com> (raw)
In-Reply-To: <4E7CD2FB.6060808@gmail.com>
References: <4E4ADB2A.5040902@gmail.com>
<4E53FE39.40501@gmail.com>
<4E6FA3DA.5090805@gmail.com>
<CADK3HHKqdj0WOBRVjZCL3o+ss5gxYA4QBC47KeNMBOhM4mCXoQ@mail.gmail.com>
<4E77155D.8050200@gmail.com>
<4E7753F7.9090903@gmail.com>
<alpine.BSO.2.00.1109191427540.603@leary.csoft.net>
<4E7CD2FB.6060808@gmail.com>
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
>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: bodri.mh3@gmail.com
Subject: Re: Prepared statement with function as argument: how to bind values?
In-Reply-To: <4E7CD3EC.2060407@gmail.com>
References: <4E4ADB2A.5040902@gmail.com> <4E53FE39.40501@gmail.com> <4E6FA3DA.5090805@gmail.com> <CADK3HHKqdj0WOBRVjZCL3o+ss5gxYA4QBC47KeNMBOhM4mCXoQ@mail.gmail.com> <4E77155D.8050200@gmail.com> <4E7753F7.9090903@gmail.com> <alpine.BSO.2.00.1109191427540.603@leary.csoft.net> <4E7CD2FB.6060808@gmail.com> <4E7CD3EC.2060407@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox