Skip to content
Related Articles

Related Articles

PostgreSQL – TEXT Data Type
  • Last Updated : 28 Aug, 2020
GeeksforGeeks - Summer Carnival Banner

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
    (
        'Geeks',
        '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
    (
        'GeeksForGeeks',
        'GeeksForGeeks 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:

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :