Обсуждение: Data Types

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

Data Types

От
"Mike Gould"
Дата:
We are converting our system from using Sybase's SQL Anywhere 10 to PostGres 8.3.  In SQL Anywhere there technically isn't any difference in how a char and varchar is stored. They are all an array of char[1]. So we always just defined everything as a char since right truncation is the default.

In PostGres though if we are using a character type column to search should we define that as a varchar or a char or does it make any difference?

Best Regards

Michael Gould
Intermodal Software Solutions, LLC.

Re: Data Types

От
"Roberts, Jon"
Дата:

Character will use more disk space than varchar so it does make a difference.

 

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

 

Values of type character are physically padded with spaces to the specified width n, and are stored and displayed that way. However, the padding spaces are treated as semantically insignificant. Trailing spaces are disregarded when comparing two values of type character, and they will be removed when converting a character value to one of the other string types. Note that trailing spaces are semantically significant in character varying and text values.

 

 

 

 

Jon

 


From: pgsql-general-owner@postgresql.org [mailto:pgsql-general-owner@postgresql.org] On Behalf Of Mike Gould
Sent: Monday, June 23, 2008 1:01 PM
To: pgsql-general General
Subject: [GENERAL] Data Types

 

We are converting our system from using Sybase's SQL Anywhere 10 to PostGres 8.3.  In SQL Anywhere there technically isn't any difference in how a char and varchar is stored. They are all an array of char[1]. So we always just defined everything as a char since right truncation is the default.

In PostGres though if we are using a character type column to search should we define that as a varchar or a char or does it make any difference?

Best Regards

Michael Gould
Intermodal Software Solutions, LLC.

Re: Data Types

От
Tom Lane
Дата:
"Roberts, Jon" <Jon.Roberts@asurion.com> writes:
> Character will use more disk space than varchar so it does make a
> difference.

char also has very peculiar comparison semantics.  Unless your strings
are really truly fixed-length, you should just about always use varchar.

            regards, tom lane

Re: Data Types

От
"Mike Gould"
Дата:
Thanks for all of the replies.

Best Regards,

Michael Gould, Manager Information Technology
All Coast Intermodal Services, Inc.
904-226-0978

From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
To: Roberts, Jon [mailto:Jon.Roberts@asurion.com]
Cc: mgould@allcoast.net, pgsql-general General [mailto:pgsql-general@postgresql.org]
Sent: Mon, 23 Jun 2008 15:00:05 -0400
Subject: Re: [GENERAL] Data Types

"Roberts, Jon" <Jon.Roberts@asurion.com> writes:
> Character will use more disk space than varchar so it does make a
> difference.

char also has very peculiar comparison semantics. Unless your strings
are really truly fixed-length, you should just about always use varchar.

regards, tom lane

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general