Postgres: Convert varchar to text
ALTER TABLE table1 ALTER COLUMN column1 TYPE text;
ALTER TABLE table1 ALTER COLUMN column1 TYPE text;
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
select column_name, data_type, character_maximum_length from information_schema.columns where table_name=”myTable”
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
The theoretical limit is really long but do you really need worry about these long Email addresses? If someone can’t login with a 100-char Email, do you really care? We actually prefer they can’t. Some statistical data may shed some light on the issue. We analyzed a database with over 10 million Email addresses. These … Read more
It is not the operator that is case sensitive, it is the column itself. When a SQL Server installation is performed a default collation is chosen to the instance. Unless explicitly mentioned otherwise (check the collate clause bellow) when a new database is created it inherits the collation from the instance and when a new … Read more
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
Let us assume the database character set is UTF-8, which is the recommended setting in recent versions of Oracle. In this case, some characters take more than 1 byte to store in the database. If you define the field as VARCHAR2(11 BYTE), Oracle can use up to 11 bytes for storage, but you may not … Read more
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) |
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