| From: | Kris Jurka <books(at)ejurka(dot)com> | 
|---|---|
| To: | Christian Rengstl <Christian(dot)Rengstl(at)klinik(dot)uni-regensburg(dot)de> | 
| Cc: | pgsql-jdbc(at)postgresql(dot)org | 
| Subject: | Re: Serial data type | 
| Date: | 2007-11-30 11:01:30 | 
| Message-ID: | Pine.BSO.4.64.0711300556200.17875@leary.csoft.net | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-jdbc | 
On Fri, 30 Nov 2007, Christian Rengstl wrote:
> in my Java app at certain points INSERT queries are built dynamically,
> but now i am facing a problem when the target table contains a SERIAL
> field where NULL values are not allowed. Therefore I have two questions:
>
> 1) How can I find out if there is a serial field in a table, as
> getColumnType() in ResultSetMetaData does not return a field indicating
> SERIAL as far as I could see?
getColumnType returns a value from java.sql.Types, which doesn't have 
SERIAL so there is no way to return it. 
ResultSetMetaData.getColumnTypeName() should probably return serial, but 
it doesn't at the moment.  ResultSetMetaData.isAutoIncrement() will work 
as will DatabaseMetaData.getColumns().
> 2) Why does it not work to issue a query like INSERT INTO 
> x(serial_field) VALUES(NULL) as the default of the "serial_field" is 
> nextval() anyway?
>
When you've explicitly supplied a value (NULL in this case) the default is 
not used.  Otherwise there would be no way to set a column to NULL that 
had a default value.
Kris Jurka
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Christian Schröder | 2007-11-30 11:07:05 | Re: Serial data type | 
| Previous Message | Christian Rengstl | 2007-11-30 10:52:39 | Serial data type |