473,750 Members | 2,533 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

varchar vs. text

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
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 11 '05 #1
4 8690
Michael Garriss <mg******@earth link.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

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 11 '05 #2
Tom Lane wrote:
Michael Garriss <mg******@earth link.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?
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 11 '05 #3
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 "correctnes s" 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. ro***********@c ox.net
Jefferson, LA USA

"(Women are) like compilers. They take simple statements and
make them into big productions."
Pitr Dubovitch
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 11 '05 #4
In article <3F************ **@earthlink.ne t>,
Michael Garriss <mg******@earth link.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
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 11 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
19708
by: Berislav Lopac | last post by:
I was lately wandering what would be the advantage of using varchar instead of text column data type in a database (specificall MySQL, but this might also be the case for other databases)? I mean, both of them are variable length, both can be indexed, and text can hold a lot more data... I'm just looking for some other opinions on the subjects. Berislav
7
2937
by: James | last post by:
I am currently working on a PHP based website that needs to be able to draw from Oracle, MS SQL Server, MySQL and given time and demand other RDBMS. I took a lot of time and care creating a flexible and solid wrapper and am deep into coding. The only problem is a noticed VARCHAR fields being drawn from SQL Server 2000 are being truncated to 255 characters. I searched around php.net and found the following : Note to Win32 Users: Due...
6
22422
by: Bill | last post by:
In an effort to improve the speed of queries against my main table, I'll be indexing a column whose data type is varchar(50). Would I be better off (better performance) if I changed the column's data type to some numeric type? I would have to update the column's data to accomodate this, but I would do it if this offers a performance gain. -- Bill
7
6218
by: Rick Caborn | last post by:
Does anyone know of a way to execute sql code from a dynamically built text field? Before beginning, let me state that I know this db architecture is built solely for frustration and I hope to make it better soon. Unfortunately, there is never a non-crucial time in which we can do an upgrade, so we are stuck for now. Point 1: There are multiple tables: students, courses, cross-reference
0
680
by: Edward Mitchell | last post by:
I have a database with text string fields defined by varchar(nnn). When I request from the user the text from a textbox, I'd like to set the maximum number of characters in the textbox to the "nnn" that was used in the varchar(...) statement in the field definition. i.e. Field1 varchar(25) NOT NULL and in the .aspx file: <asp.textbox id=Field1 runat="server" />
5
29495
by: dmhendricks | last post by:
Greetings, I have a question. I work on some SQL2k/ASP.NET apps at work. My predacessor, who created the databases/tables seemed to have liked to use 'char' for all text fields. Is there a reason why he would have done this over using varchar? It's a minor annoyance to always have to RTRIM data and it makes directly making changes to the database more annoying (with all the pointless trailing spaces)? I usually use char for fixed...
10
71101
by: Techie | last post by:
what's the difference of the two data types?
6
12909
by: mike | last post by:
so I keep optimizing my fields down to the minimum character length necessary i.e., varchar(15), then I find out a month later its gotta get bigger, then a few months later, bigger again, etc. Nowadays on sql server 2005 and on, how bad is it really to use varchar(max)? Is there really a big performance or storage hit or is it negligible? -Mike
0
1739
Krishna Ladwa
by: Krishna Ladwa | last post by:
In Sql Server 2000 Version, I found that no Notification message box appears when converting text column to varchar but the data gets truncated to the given size for the varchar. Whereas it appears when you convert the varchar column to text column. Do this through Enterprise Manager Console Create a New table with a column as varchar datatype from Enterprise Manager  table created  Open the table and add one row  Successfully added the...
4
8869
by: Nick Chan | last post by:
all these while i've only used varchar for any string i heard from my ex-boss that char helps speed up searches. is that true? so there are these: 1) char with index 2) char without index 3) char with clustered index
0
8838
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9583
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9396
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9256
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6081
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4716
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4888
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2226
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.