MySQL VARCHAR Lengths and UTF-8

This answer showed up at the top of my google search results but wasn’t correct. The confusion is probably due to different versions of MySQL being tested. Version 4 counts bytes Version 5 counts characters Here is the quote from the official MySQL 5 documentation: MySQL interprets length specifications in character column definitions in character … Read more

PostgreSQL: ERROR: operator does not exist: integer = character varying

I think it is telling you exactly what is wrong. You cannot compare an integer with a varchar. PostgreSQL is strict and does not do any magic typecasting for you. I’m guessing SQLServer does typecasting automagically (which is a bad thing). If you want to compare these two different beasts, you will have to cast … Read more

What is the difference between CHARACTER VARYING and VARCHAR in PostgreSQL?

VARCHAR is an alias for CHARACTER VARYING, so no difference, see documentation 🙂 The notations varchar(n) and char(n) are aliases for character varying(n) and character(n), respectively. character without length specifier is equivalent to character(1). If character varying is used without length specifier, the type accepts strings of any size. The latter is a PostgreSQL extension. … Read more

Postgresql – change the size of a varchar column to lower length

In PostgreSQL 9.1 there is an easier way http://www.postgresql.org/message-id/162867790801110710g3c686010qcdd852e721e7a559@mail.gmail.com CREATE TABLE foog(a varchar(10)); ALTER TABLE foog ALTER COLUMN a TYPE varchar(30); postgres=# \d foog Table “public.foog” Column | Type | Modifiers ——–+———————–+———– a | character varying(30) |

Is there a good reason I see VARCHAR(255) used so often (as opposed to another length)?

255 is used because it’s the largest number of characters that can be counted with an 8-bit number. It maximizes the use of the 8-bit count, without frivolously requiring another whole byte to count the characters above 255. When used this way, VarChar only uses the number of bytes + 1 to store your text, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)