Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 55D59632D08 for ; Fri, 8 Jan 2010 22:30:44 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 61619-03 for ; Sat, 9 Jan 2010 02:30:25 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from outbound.vnet-inc.com (outbound.vnet-inc.com [216.146.104.103]) by mail.postgresql.org (Postfix) with ESMTP id B77E0632BEF for ; Fri, 8 Jan 2010 22:30:33 -0400 (AST) Received: from [192.168.157.32] (unknown [216.129.226.110]) by outbound.vnet-inc.com (Postfix) with ESMTP id A109E5A08; Fri, 8 Jan 2010 19:30:32 -0700 (MST) Message-ID: <4B47E6A5.2090009@ttc-cmc.net> Date: Fri, 08 Jan 2010 19:15:01 -0700 From: dmp User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.13) Gecko/20060417 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Johnny Luong , pgsql-jdbc@postgresql.org Subject: Re: issuing insert preparedstatement queries with default values References: <4B47C7E9.4030000@trustcommerce.com> In-Reply-To: <4B47C7E9.4030000@trustcommerce.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=-2.301 tagged_above=-10 required=5 tests=AWL=0.298, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201001/3 X-Sequence-Number: 20199 > -----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