varchar vs. text

Started by Michael Garrissover 22 years ago5 messagesgeneral
Jump to latest
#1Michael Garriss
mgarriss@earthlink.net

I curious about the benefits of a varchar over text. Is it speed,
size? If so, how much speed, size? Is a varchar(64) and a text with 64
chars the same size? I'm inclined to make all my varchars into text so
I don't have to worry about inserting something to big.

TIA,
Michael

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Michael Garriss (#1)
Re: varchar vs. text

Michael Garriss <mgarriss@earthlink.net> writes:

I curious about the benefits of a varchar over text.

1. Compliance to the letter of the SQL spec.
2. Ability to define a maximum length, if you happen to feel the need to
impose a specific maximum length. (If you don't have a good reason
to impose any particular max length, this is a minus not a plus,
because the spec says you have to pick one anyway.)

Is it speed,

It's a loser on speed because of the extra cycles spent to check the
max length. Other than those cycles, there is no difference.

regards, tom lane

#3Michael Garriss
mgarriss@earthlink.net
In reply to: Tom Lane (#2)
Re: varchar vs. text

Tom Lane wrote:

Michael Garriss <mgarriss@earthlink.net> writes:

I curious about the benefits of a varchar over text.

1. Compliance to the letter of the SQL spec.
2. Ability to define a maximum length, if you happen to feel the need to
impose a specific maximum length. (If you don't have a good reason
to impose any particular max length, this is a minus not a plus,
because the spec says you have to pick one anyway.)

Is it speed,

It's a loser on speed because of the extra cycles spent to check the
max length. Other than those cycles, there is no difference.

regards, tom lane

Thanks for the quick response.

Michael

P.S. The code I'm writing is going to be ported to MySQL by a friend.
Do you have any idea if TEXT is supported over there?

#4Ron Johnson
ron.l.johnson@cox.net
In reply to: Michael Garriss (#1)
Re: varchar vs. text

On Wed, 2003-09-17 at 22:59, Michael Garriss wrote:

I curious about the benefits of a varchar over text. Is it speed,
size? If so, how much speed, size? Is a varchar(64) and a text with 64
chars the same size? I'm inclined to make all my varchars into text so
I don't have to worry about inserting something to big.

An analyst would say that "correctness" is a reason for specifying
a max length. For example, in t_names, I could stick "War and Peace"
into first_name, but, obviously, that's not "correct".

CREATE TABLE t_names (
first_name TEXT,
last_name TEXT );

--
-----------------------------------------------------------------
Ron Johnson, Jr. ron.l.johnson@cox.net
Jefferson, LA USA

"(Women are) like compilers. They take simple statements and
make them into big productions."
Pitr Dubovitch

#5Harald Fuchs
nospam@sap.com
In reply to: Michael Garriss (#1)
Re: varchar vs. text

In article <3F69366B.6080902@earthlink.net>,
Michael Garriss <mgarriss@earthlink.net> writes:

P.S. The code I'm writing is going to be ported to MySQL by a friend.

Shame on you for having a friend using MySQL ;-)

Do you have any idea if TEXT is supported over there?

Yes: http://www.mysql.com/doc/en/BLOB.html