Re: default values - Mailing list pgsql-jdbc

From David Wall
Subject Re: default values
Date
Msg-id 004801c28e9d$9d951cc0$3201a8c0@expertrade.com
Whole thread Raw
In response to default values  ("Felipe Schnack" <felipes@ritterdosreis.br>)
List pgsql-jdbc
> default value of a column using DEFAULT keyword on pgsql 7.3. Example:
>   INSERT INTO TEST (varcharfield1, varcharfield2) VALUES ('text', DEFAULT)
>   In this case, the "varcharfield2" column would get its default value (as
> defined in CREATE TABLE). I was wondering, how I would do it using
> PreparedStatements? If I prepare an SQL like
>   INSERT INTO TEST (varcharfield1, varcharfield2) VALUES (?, ?)
>   I need to have some way to set one of the the parameters as DEFAULT, but
> how? Using the current JDBC driver I believe is impossible, probably we
would
> need something like a "setDefault(int)" method in PreparedStatement, where
int
> is the parameter index. What do you think about it?
>

Why not simply remove varcharfield2 from the INSERT statement and let the
database insert that value with the default value?  Isn't the purpose of a
default value to have the DB put that value in when none is specified?

David


pgsql-jdbc by date:

Previous
From: Nic Ferrier
Date:
Subject: Re: streaming result sets: progress
Next
From: Nic Ferrier
Date:
Subject: Re: streaming result sets: progress