PostgreSQL/Data Type/varchar

Материал из SQL эксперт
Версия от 13:14, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

varchar with length

   <source lang="sql">

postgres=# postgres=# CREATE TABLE test2 (b varchar(5)); CREATE TABLE postgres=# postgres=# INSERT INTO test2 VALUES ("ok"); INSERT 0 1 postgres=# INSERT INTO test2 VALUES ("good "); INSERT 0 1 postgres=# INSERT INTO test2 VALUES ("too long"); ERROR: value too long for type character varying(5) postgres=# postgres=# INSERT INTO test2 VALUES ("too long"::varchar(5)); -- explicit truncation INSERT 0 1 postgres=# SELECT b, char_length(b) FROM test2;

  b   | char_length

+-------------
ok    |           2
good  |           5
too l |           5

(3 rows) postgres=# postgres=# drop table test2; DROP TABLE postgres=# postgres=#

      </source>