char() or varchar() for frequently used column

Поиск
Список
Период
Сортировка
От Jules Alberts
Тема char() or varchar() for frequently used column
Дата
Msg-id 200210170724.g9H7OQTY018412@artemis.cuci.nl
обсуждение исходный текст
Ответы Re: char() or varchar() for frequently used column  ("paul butler" <paul@entropia.co.uk>)
Re: char() or varchar() for frequently used column  ("Josh Berkus" <josh@agliodbs.com>)
Список pgsql-novice
Hello everyone,

A db I'm designing will have a lot of tables with codes in them, like

create table country (
    id serial primary key,
    code char(2) not null unique,
    name varchar(100) not null unique);
insert into country (code, name) values ('NL', 'Nederland');
insert into country (code, name) values ('BE', 'Belgie');
-- etc

create table gender (
    id serial primary key,
    code char(1) not null unique,
    name varchar(100) not null unique);
insert into gender (code, name) values ('M', 'male');
insert into gender (code, name) values ('F', 'female');

The 'code' columns will be used as foreign keys in other tables. My
question is about the datatype and length of the 'code' columns.
Allthough the codes length will probably not change over the years, it
might happen anyway. I've seen this before and had some headaches over
it. So in the new db I want to be prepared and make the referenced
columns longer than would appear necessary at first sight. So instead
of "code char(2)" I plan to do "code varchar(25)". The idea is that I:

- give myself space for future and unforeseeable change of the length
- don't waste space by using varchar() instead of char()

Are there any flaws in this approach? Will I get in trouble when using
indexes. Will performance be hampered severely? (we're not talking
about huge amounts of transactions)

Thanks for any insight!

В списке pgsql-novice по дате отправления:

Предыдущее
От: "Jules Alberts"
Дата:
Сообщение: Re: db design question
Следующее
От: "paul butler"
Дата:
Сообщение: Re: char() or varchar() for frequently used column