From: | Steve Pothier <pothiers(at)nemesis(dot)tucson(dot)saic(dot)com> |
---|---|
To: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | how can I recover from truncate write? |
Date: | 2002-11-15 16:55:37 |
Message-ID: | 200211151655.gAFGtbG4030646@payson.tucson.saic.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
If I attempt to write a field to the DB that is too long, I get an
SQLException (not SQLWarning, not DataTrunctation). The INSERT
apparently fails. I'ld like to issue a warning and automatically
truncate to fit. Given that I only get a general SQLException,
PROGRAMATICALLY its difficult to know that I got a data truncation (as
opposed to other exception) and if truncation, its difficult to know
how long the field is allowed to be (or even which field failed).
SQLException.getMessage() yields: "value too long for type character
varying(20)" so I COULD parse that message but that seems horrid.
Any better ideas?
The doc http://lab.applinet.nl/postgresql-jdbc/ discusses two
conflicting readings on what should happen with regard to data
truncation. I just tried some tests and neither approaches work
(ie. the truncation is not reported by Statement.getWarnings(), and
is not thrown as an SQLWarning or DataTruncation exceptions). I think
this means the driver is guaranteed to be wrong (and hard to use in
the face of truncations!)
The doc already warns that DataTruncation is never thrown. It does not
point out that Statement.getWarnings also does not work for data
truncation errors.
-Steve-
From | Date | Subject | |
---|---|---|---|
Next Message | David Wall | 2002-11-15 17:11:13 | Re: PostgreSQL/Oracle/MSSQL differences (was: streaming result |
Previous Message | Felipe Schnack | 2002-11-15 16:10:28 | default values in queries |