pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: dmp <danap@ttc-cmc.net>
To: PostgreSQL JDBC <pgsql-jdbc@postgresql.org>
Subject: Re: preparedStatement, Batch, DEFAULT,  getGeneratedKeys()
Date: Mon, 18 Nov 2013 11:41:46 -0700
Message-ID: <528A5F6A.8030508@ttc-cmc.net> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>

Martin Eriksson wrote:
 > Hi,
 >
 > I've been scourging the mailing list for a while and general
 > google/stack overflow looking for a solution dealing with JDBC, and
 > batching..
 >
 >    2. I've been searching and searching for a way to set "DEFAULT" on a
 >       prepared statement, is it even possible? e.g. "INSERT INTO a (id)
 >       VALUES (?) and then doing something like
 >       prepStatment.setInt(1,"DEFAULT"); I have found no way of doing
 >       this... when doing big batches that would be very nice indeed....
 >       to not having to split everything depending on the existence of
 >       data in default fields
 >
 > Cheers
 > Martin
 >

Hello Martin,

With regard to 2.

Some databases do allow you to insert default in the prepared statement,
but I have not found that to be the case with PostgreSQL to my knowledge.

Default can be inserted though via the following.

Given:

CREATE TABLE "keY_tAble2" (
   "Host" char(60) NOT NULL default '',
   "Db" char(64) NOT NULL default '',
   "Username" char(16) NOT NULL default '',
   Select_priv boolean NOT NULL default TRUE,
   PRIMARY KEY ("Host","Db","Username")
);

To give the default value to "Host" Use the following prepared statement.

INSERT INTO "public"."keY_tAble2" ("Db", "Username", "select_priv") VALUES (?, ?, ?)

I guess as you said though this does not help with batching.

danap.



-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



view thread (2+ messages)

Message-ID: <528A5F6A.8030508@ttc-cmc.net>
Permalink:  ../528A5F6A.8030508@ttc-cmc.net/
Also on:    postgresql.org/message-id/528A5F6A.8030508@ttc-cmc.net

 · 

reply

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: danap@ttc-cmc.net
  Subject: Re: preparedStatement, Batch, DEFAULT,  getGeneratedKeys()
  In-Reply-To: <528A5F6A.8030508@ttc-cmc.net>
  References: <528A5F6A.8030508@ttc-cmc.net>

* 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