Обсуждение: CHAR data type

Поиск
Список
Период
Сортировка

CHAR data type

От
"Leticia"
Дата:

I am using PostgreSQL 8.2.3. with the default page size of 8K

 

I created the following table:

 

CREATE TABLE mystate( ID integer, name char(8000) );

 

I inserted three tuples:

 

INSERT INTO mystate VALUES (3, 'a3');

INSERT INTO mystate VALUES (5, 'a5');

INSERT INTO mystate VALUES (6, 'a6');

 

And then I ran the following query:

 

vacuum analyze mystate;          

select relpages, reltuples from pg_class where relname='mystate';

 

 

but the result was:

1                 3

 

 

If I use “char(8000)” instead of “varchar(8000)” why there is no padding and these three tuples are inside the same page?

 

Thanks in advance,

Leticia

 

 

Вложения

Re: CHAR data type

От
Michael Fuhr
Дата:
On Wed, Mar 21, 2007 at 11:29:54AM -0300, Leticia wrote:
> If I use "char(8000)" instead of "varchar(8000)" why there is no padding and
> these three tuples are inside the same page?

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

"The storage requirement for data of these types is 4 bytes plus
the actual string, and in case of character plus the padding. Long
strings are compressed by the system automatically, so the physical
requirement on disk may be less. Long values are also stored in
background tables so they do not interfere with rapid access to the
shorter column values."

See also the TOAST documentation:

http://www.postgresql.org/docs/8.2/interactive/storage-toast.html

--
Michael Fuhr