Open In App

PostgreSQL – TEXT Data Type

Improve
Improve
Like Article
Like
Save
Share
Report

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:


Last Updated : 28 Aug, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads