| From: | Barry Lind <blind(at)xythos(dot)com> |
|---|---|
| To: | oic2day(at)yahoo(dot)com |
| Cc: | pgsql-jdbc(at)postgresql(dot)org |
| Subject: | Re: how can I recover from truncate write? |
| Date: | 2002-11-16 03:28:22 |
| Message-ID: | 3DD5BB56.6050300@xythos.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-jdbc |
Steve,
There really is no good way to do this. The database is generating the
error. And actually the SQL standard says this is supposed to be an
error condition. So I am not sure anything should be changed in either
the driver or the database. You really need to test the data before
sending it to the driver.
thanks,
--Barry
Steve Pothier wrote:
> 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-
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Marko Štrukelj | 2002-11-16 11:52:32 | jdbc bug/fetaure? |
| Previous Message | Barry Lind | 2002-11-16 03:17:21 | Re: postgreSQL 7.2.3: jdbc compile problem |