首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 操作系统 >

Postgresql 安插数据时自动截取一定长度的字符串

2013-07-08 
Postgresql 插入数据时自动截取一定长度的字符串5.1.1.?自动截取字符串CREATE TABLE test (c varchar(5))

Postgresql 插入数据时自动截取一定长度的字符串

5.1.1.?自动截取字符串
CREATE TABLE test (c varchar(5));

现在开始插入数据库,每次增加一个长度

test=> INSERT INTO test VALUES ('1');INSERT 0 1test=> INSERT INTO test VALUES ('12');INSERT 0 1test=> INSERT INTO test VALUES ('123');INSERT 0 1test=> INSERT INTO test VALUES ('1234');INSERT 0 1test=> INSERT INTO test VALUES ('12345');INSERT 0 1test=> INSERT INTO test VALUES ('123456');ERROR:  value too long for type character varying(5)test=> INSERT INTO test VALUES ('1234567');ERROR:  value too long for type character varying(5)test=>

超出长度会提示 ERROR: value too long for type character varying(5)

通过 ::varchar(5) 截取5前五个字符,后面抛弃

test=> INSERT INTO test VALUES ('123456'::varchar(5));INSERT 0 1test=> INSERT INTO test VALUES ('1234567'::varchar(5));INSERT 0 1test=> INSERT INTO test VALUES ('12345678'::varchar(5));INSERT 0 1

超过的部分被自动截取

test=> select * from test;   c------- 1 12 123 1234 12345 12345 12345 12345(8 rows)

热点排行