I know very little about Postgres, but I see this interesting page in their
documentation:

http://www.postgresql.org/docs/8.0/interactive/datatype-character.html

Excerpt:

*An attempt to store a longer string into a column of these types will
result in an error, unless the excess characters are all spaces, in which
case the string will be truncated to the maximum length. (This somewhat
bizarre exception is required by the SQL standard.) If the string to be
stored is shorter than the declared length, values of type character will
be space-padded; values of type character varying will simply store the
shorter string.*

*If one explicitly casts a value to character varying(n) or character(n),
then an over-length value will be truncated to n characters without raising
an error. (This too is required by the SQL standard.)*

*Note: Prior to PostgreSQL 7.2, strings that were too long were always
truncated without raising an error, in either explicit or implicit casting
contexts.*


----
I tried a simple test with recent (9.3.4) version (using default settings,
if that matters) and verified that an insert with oversized string will
fail to insert, unless the overage characters are spaces only, in which
case it succeeds with truncation.   I did NOT experiment with number
conversions, nor with a version prior to 7.2, nor did I attempt to review
the sql standards.

---------
drop table if exists j2;
create table j2( a2 varchar(2), b3 varchar(3));
insert into j2 values ('a', 'b');
-- following will fail with error
insert into j2 values ('aaaaaaa', 'bbbbbbb');

ERROR:  value too long for type character varying(2)
********** Error **********

-- but following insert will succeed with truncated column b3
insert into j2 values ('aa', 'bbb        ');
select *, length(b3) from j2;

Output was:
"a";"b";1
"aa";"bbb";3

Donald
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to