Re: Parameterized queries

Lists: pgsql-interfaces
From: "Jan Klostermann" <klostermann(at)rhf(dot)de>
To: <pgsql-interfaces(at)postgresql(dot)org>
Subject: Parameterized queries
Date: 2003-11-14 16:05:46
Message-ID: 001b01c3aac9$2a7d77c0$f564a8c0@BARCELONA
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-interfaces

Hello,

I would like to know, if there exists a way in PostgreSQL to insert data
not exclusively via the SQL-query-string but using a direct data
interface, thus avoiding parsing the data into string and then back into
binary data representation (e.g. Double).

What I would like to use is a query like this: INSERT INTO table
(number1, number2) VALUES (?,?)
Before executing the query the command structure would be fill with the
parameters for the 2 values (e.g. 3.33 and 5.555) and then there would
follow the execution, where the query parser would replace the "?" with
the current data of the parameters and execute the appopriate query.

Unfortunately I cannot find anything about query-contructions with
question marks ("?"), therefore I am already wondering if this way of
transfering data exists with PostgreSQL!?

Is there anybody out there, who can help me with this?
Is there another way of efficiently transfering data, avoiding parsing
back and forth?

Jan Klostermann

PS: I tried to do it via the ODBC interface and it did not work. Then I
scanned through the documentation, incl. libpq and did not find anything
related.


From: "Jeroen T(dot) Vermeulen" <jtv(at)xs4all(dot)nl>
To: Jan Klostermann <klostermann(at)rhf(dot)de>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: Parameterized queries
Date: 2003-11-14 16:28:40
Message-ID: 20031114162840.GC9538@xs4all.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-interfaces

On Fri, Nov 14, 2003 at 05:05:46PM +0100, Jan Klostermann wrote:
>
> I would like to know, if there exists a way in PostgreSQL to insert data
> not exclusively via the SQL-query-string but using a direct data
> interface, thus avoiding parsing the data into string and then back into
> binary data representation (e.g. Double).

You could use binary cursors.

> What I would like to use is a query like this: INSERT INTO table
> (number1, number2) VALUES (?,?)
> Before executing the query the command structure would be fill with the
> parameters for the 2 values (e.g. 3.33 and 5.555) and then there would
> follow the execution, where the query parser would replace the "?" with
> the current data of the parameters and execute the appopriate query.

Wouldn't it be easier in this case to skip the SQL altogether and just
use the COPY command to pump data into the table with minimal processing?
You'd still go through the parsing, but that may end up saving you trouble
anyway if you ever need to run the server and the client on different
machines--and I wouldn't be surprised if going through SQL is costing you
more than the value parsing anyway.

From what I've heard, COPY (or tablewriter if you use libpqxx) is much
faster than SQL INSERT.

Jeroen


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Jan Klostermann" <klostermann(at)rhf(dot)de>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: Parameterized queries
Date: 2003-11-14 16:41:57
Message-ID: 26687.1068828117@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-interfaces

"Jan Klostermann" <klostermann(at)rhf(dot)de> writes:
> I would like to know, if there exists a way in PostgreSQL to insert data
> not exclusively via the SQL-query-string but using a direct data
> interface,

This ability exists as of 7.4. I do not know whether the ODBC interface
supports it, but libpq does and I believe JDBC does.

regards, tom lane