PostgreSQL – TEXT Data Type
PostgreSQL supports a character data type called TEXT. This data type is used to store character of unlimited length. It is represented as text
in PostgreSQL. The performance of the varchar (without n) and text are the same.
Syntax: variable_name TEXT
Example 1:
Let’s create a new table(say, text_test) for the demonstration using the below commands:
CREATE TABLE text_test ( id serial PRIMARY KEY, x TEXT, y TEXT );
Now let’s insert a new row into the char_test table using the below command:
INSERT INTO text_test (x, y) VALUES ( 'Beginner', 'This is a test for char' );
Now that we have managed to successfully assign the values to the character data type, check it by running the below command:
SELECT * FROM text_test;
Output:
Example 2:
Let’s create a new table(say, text_test2) for the demonstration using the below commands:
CREATE TABLE text_test2 ( id serial PRIMARY KEY, a TEXT, b TEXT );
Now let’s insert a new row into the char_test table using the below command:
INSERT INTO text_test2 (a, b) VALUES ( 'w3wiki', 'w3wiki is the Best.' );
Now that we have managed to successfully assign the values to the character data type, check it by running the below command:
SELECT * FROM text_test2;
Output:
Contact Us