Re: default values

From: Felipe Schnack <felipes(at)ritterdosreis(dot)br>
To: pgsql-jdbc <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: default values
Date: 2002-11-18 11:19:35
Message-ID: 1037618375.1308.5.camel@desenv1.ritterdosreis.br
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Maybe setting null will put the default value in a not null field?
Anyway, in a nullable field null must be inserted.
I would want to have a setDefault() method for a simple reason
actually... laziness :-)
The real reason is that in the application i'm working on, we don't
put SQL queries inside java code, it's stored separated, in a XML file.
So if quite boring to type lots of sqls when all you wanted is to omit
the field from the query (we can't build queries using java code).
Anyway, I wasn't so worried about have to type all these commands, but I
heard pgsql have this feature, so would be nice if the driver supports
it.
What do you think about it? I hear this is a 7.3 new feature.

On Mon, 2002-11-18 at 01:07, Dave Cramer wrote:
> 1) Yes, it does happen automatically, and to invoke it when it is in the
> insert statement, just use setNull
>
> Dave
> On Sun, 2002-11-17 at 21:06, Dror Matalon wrote:
> > Two ideas:
> >
> > 1. If you don't include the variable in your insert statement, doesn't
> > the default value happen automatically? In this case
> > INSERT INTO TEST (varcharfield1) VALUES (?), should result in
> > varcharfield2 getting its default value.
> >
> > 2. This is a longer shot ...
> >
> > does this work?
> >
> > INSERT INTO TEST (varcharfield1, varcharfield2) VALUES (?, DEFAULT)
> >
> >
> > Dror
> >
> >
> >
> > On Sun, Nov 17, 2002 at 09:30:15PM -0100, Felipe Schnack wrote:
> > > This is the third time I post this message. Nobody have ANY opinion about
> > > it? I mean, I'm willing to implement a solution for this, but I would like to
> > > discuss a little...
> > > Someone wrote to pgsql general list telling that you could insert the
> > > 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?
> > >
> > > Felipe Schnack
> > > Analista de Sistemas
> > > felipes(at)ritterdosreis(dot)br
> > > Cel.: (51)91287530
> > > Linux Counter #281893
> > >
> > > Faculdade Ritter dos Reis
> > > www.ritterdosreis.br
> > > felipes(at)ritterdosreis(dot)br
> > > Fone/Fax.: (51)32303328
> > >
> > >
> > > ---------------------------(end of broadcast)---------------------------
> > > TIP 6: Have you searched our list archives?
> > >
> > > http://archives.postgresql.org
> --
> Dave Cramer <Dave(at)micro-automation(dot)net>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
--

Felipe Schnack
Analista de Sistemas
felipes(at)ritterdosreis(dot)br
Cel.: (51)91287530
Linux Counter #281893

Faculdade Ritter dos Reis
www.ritterdosreis.br
felipes(at)ritterdosreis(dot)br
Fone/Fax.: (51)32303328

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Haris Peco 2002-11-18 14:37:04 Re: streaming result sets: progress
Previous Message Dave Cramer 2002-11-18 10:34:52 Re: default values