472,141 Members | 1,581 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,141 software developers and data experts.

char o varchar



Hoii!!

I am creating my struct and I have the question :
What I must use for character fields char or varchar?
Which are the differences? and the better
TIA

*-------------------------------------------------------*
*-Edwin Quijada
*-Developer DataBase
*-JQ Microsistemas
*-809-747-2787
* " Si deseas lograr cosas excepcionales debes de hacer cosas fuera de lo
comun"
*-------------------------------------------------------*

__________________________________________________ _______________
Charla con tus amigos en línea mediante MSN Messenger:
http://messenger.yupimsn.com/
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 11 '05 #1
3 2074
On Tue, 16 Sep 2003, Edwin Quijada wrote:


Hoii!!

I am creating my struct and I have the question :
What I must use for character fields char or varchar?
Which are the differences? and the better


Generally speaking, varchar or text() types are preferred. char() types
are padded. I.e. if you create a table with char(8) and insert 'abc' then
select it, you'll get 'abc ' back, i.e. abc followed by padding spaces
to make it 8 wide.

Most of the time this is not what the user wants.
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 11 '05 #2
As of my knowlege, varchar as the choice when you have varying lenght
strings, because only the real string lenght is stored in the db, while
char is usefull when most of your records ar exactly the stringlenght
defined by the column, because no overhead is to be kept for storing the
actual stringlenght.

Regards

Edwin Quijada wrote:


Hoii!!

I am creating my struct and I have the question :
What I must use for character fields char or varchar?
Which are the differences? and the better
TIA

*-------------------------------------------------------*
*-Edwin Quijada
*-Developer DataBase
*-JQ Microsistemas
*-809-747-2787
* " Si deseas lograr cosas excepcionales debes de hacer cosas fuera de
lo comun"
*-------------------------------------------------------*

__________________________________________________ _______________
Charla con tus amigos en línea mediante MSN Messenger:
http://messenger.yupimsn.com/
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

--
Andreas Fromm

-----------------------------
Drink wet cement...
... and get stoned


---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 11 '05 #3
On Wed, Sep 17, 2003 at 09:11:54AM +0200, Andreas Fromm wrote:
As of my knowlege, varchar as the choice when you have varying lenght
strings, because only the real string lenght is stored in the db, while
char is usefull when most of your records ar exactly the stringlenght
defined by the column, because no overhead is to be kept for storing the
actual stringlenght.


No, the overhead is present for char(n) as well, because it stores the
length in _bytes_ while the "n" is the length in characters; they could
be different.

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
One man's impedance mismatch is another man's layer of abstraction.
(Lincoln Yeoh)

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 11 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Randell D. | last post: by
5 posts views Thread by dmhendricks | last post: by
10 posts views Thread by Techie | last post: by
22 posts views Thread by jdokos | last post: by
1 post views Thread by Troels Arvin | last post: by
4 posts views Thread by Nick Chan | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.