0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

postgreSQLでVARCHARとCHARを試した

Posted at

バージョン:psql (PostgreSQL) 11.1

(n)なしでCHAR

postgres=# create table tmp1 (name CHAR);
CREATE TABLE
postgres=# insert into tmp1 values ('aaa');
ERROR:  value too long for type character(1)
postgres=# insert into tmp1 values ('aa');
ERROR:  value too long for type character(1)
postgres=# insert into tmp1 values ('a');
INSERT 0 1
postgres=#

(n)なしでVARCHAR

postgres=# create table tmp2 (name VARCHAR);
CREATE TABLE
postgres=# insert into tmp2 values ('aaa');
INSERT 0 1
postgres=#

CHAR(1)にしてみる

postgres=# create table tmp3 (name CHAR(1));
CREATE TABLE
postgres=# insert into tmp3 values ('aaa');
ERROR:  value too long for type character(1)
postgres=# insert into tmp3 values ('aa');
ERROR:  value too long for type character(1)
postgres=# insert into tmp3 values ('a');
INSERT 0 1
postgres=#

VARCHAR(1)にしてみる

postgres=# create table tmp4 (name VARCHAR(1));
CREATE TABLE
postgres=# insert into tmp4 values ('aaa');
ERROR:  value too long for type character varying(1)
postgres=# insert into tmp4 values ('aa');
ERROR:  value too long for type character varying(1)
postgres=# insert into tmp4 values ('a');
INSERT 0 1
postgres=#
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?