in the documents
(https://www.postgresql.org/docs/current/typeconv-query.html),there is the
following descrition:
“blank-padded char”, the internal name of the character data type.
===>>so bpchar datatype is equal to character data type
in the documents
(https://www.postgresql.org/docs/15/datatype-character.html),there is the
following descrition:
character without length specifier is equivalent to character(1).
===>>so character data type is equal to character(1) data type
Based on the above description, there is a deduction as follows:
bpchar datatype is equal to character(1) data type
but the following test tells us that: bpchar datatype is not equal to
character(1) data type.
I want to know why? Maybe the document has error? and I want to know that:
bpchar datatype is equal to which datatype?
postgres=# select version();
version
---------------------------------------------------------------------------------------------------------
PostgreSQL 15.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623
(Red Hat 4.8.5-44), 64-bit
(1 row)
postgres=# create table xxx2(c1 char,c2 int);
CREATE TABLE
postgres=# insert into xxx2 values('aaaaa',1);
ERROR: value too long for type character(1) <<<<----please note this
error!
postgres=# \d+ xxx2;
Table "public.xxx2"
Column | Type | Collation | Nullable | Default | Storage |
Compression | Stats target | Description
--------+--------------+-----------+----------+---------+----------+-------------+--------------+-------------
c1 | character(1) | | | | extended |
| |
c2 | integer | | | | plain |
| |
Access method: heap
postgres=# create table xxx3(c1 bpchar,c2 int);
CREATE TABLE
postgres=# insert into xxx3 values('aaaaa',1);
INSERT 0 1
postgres=# \d+ xxx3;
Table "public.xxx3"
Column | Type | Collation | Nullable | Default | Storage | Compression |
Stats target | Description
--------+---------+-----------+----------+---------+----------+-------------+--------------+-------------
c1 | bpchar | | | | extended | |
|
c2 | integer | | | | plain | |
|
Access method: heap
postgres=# select * from xxx3; <<<<----please note this result.
c1 | c2
-------+----
aaaaa | 1
(1 row)
postgres=#