Reputation: 377
What is the difference between the following two data types?
I thought that character varying[]
is used when we want to use also Length constraint. However, from what I see within pgAdmin, we can use this constraint also with character varying
.
Upvotes: 3
Views: 5506
Reputation: 175616
Text vs array of text. It represents single user name with possible multiple emails stored as array of type VARCHAR(100)
.
CREATE TABLE tab(
username character varying(100),
email character varying(100)[]
);
INSERT INTO tab(username, email) VALUES ('user', '{"[email protected]", "[email protected]"}');
SELECT *, email[1], email[2]
FROM tab;
Output:
+-----------+------------------------------+---------------+--------------+
| username | email | email | email |
+-----------+------------------------------+---------------+--------------+
| user | {[email protected],[email protected]} | [email protected] | [email protected] |
+-----------+------------------------------+---------------+--------------+
Upvotes: 4
Reputation: 311188
"character varying" (or varchar, for short) is a string (text) field with varying length (up to 100 characters in your case). The []
denotes an array. I.e., "character varying[]" is an array of such "character varying" strings.
Upvotes: 2