pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: dmp <danap@ttc-cmc.net>
To: Johnny Luong <johnny.luong@trustcommerce.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: issuing insert preparedstatement queries with default values
Date: Fri, 08 Jan 2010 19:15:01 -0700
Message-ID: <4B47E6A5.2090009@ttc-cmc.net> (raw)
In-Reply-To: <4B47C7E9.4030000@trustcommerce.com>
References: <4B47C7E9.4030000@trustcommerce.com>

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi,
>
> Is there a way to use the DEFAULT per column value on an INSERT sql in
> PG through the PreparedStatement JDBC API?  It'd be nice so that I don't
> have to maintain a secondary list of PreparedStatements or a list of
> default values maintained outside of the database definition.
>
> e.g:
>
> INSERT INTO foo (a, b) (?, ?)
>
> where b has a default value in the database and a is something that I
> might set to some other value.
>
>
> I'm using postgresql-8.3-603.jdbc4.jar against a 8.3 postgresql server.
>
> Thanks,
> Johnny 


I know this may be not the appropriate approach, but when a user enters
default I just skip the PrepareStatement value assignment for that field
and set in the initial assignment as such. See example below.

danap.


--
-- MyJSQLView SQL Dump
-- Version: 3.06
-- WebSite: http://myjsqlview.org
--
-- Host: 127.0.0.1
-- Generated On: 2010.01.08 AD at 07:07:55 MST
-- SQL version: PostgreSQL 8.3.3
-- Database: key_tables
--

-- ------------------------------------------

--
-- Table structure for table "public"."key_table4"
--

CREATE TABLE "public"."key_table4" (
    "avatar_id" integer DEFAULT 0 NOT NULL,
    "user_id" integer DEFAULT 0 NOT NULL,
    "bing_id" smallint DEFAULT 0 NOT NULL,
    PRIMARY KEY ("avatar_id","user_id")
);

TableEntryForm addUpdateTableEntry() Connection Created
INSERT INTO "public"."key_table4" ("avatar_id", "user_id", "bing_id") 
VALUES (?, ?, default)
TableEntryForm addUpdateTableEntry() Connection Closed



view thread (4+ messages)  latest in thread

Message-ID: <4B47E6A5.2090009@ttc-cmc.net>
Permalink:  ../4B47E6A5.2090009@ttc-cmc.net/
Also on:    postgresql.org/message-id/4B47E6A5.2090009@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, johnny.luong@trustcommerce.com
  Subject: Re: issuing insert preparedstatement queries with default values
  In-Reply-To: <4B47E6A5.2090009@ttc-cmc.net>
  References: <4B47C7E9.4030000@trustcommerce.com> <4B47E6A5.2090009@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