← Back to PostgreSQL Course | Chapter 3: Data Types | Lesson 2 of 7

VARCHAR और TEXT

text किसी भी length की strings store करता है जबकि varchar(n) एक maximum length enforce करता है।

In this page:

  1. VARCHAR/TEXT
Syntax
sql
column_name varchar(n)
column_name text

VARCHAR/TEXT

PostgreSQL में text और बिना length वाला varchar identically perform करते हैं, और varchar(n) एक length check add करता है जो exceed होने पर एक error raise करता है। char(n) spaces से pad करता है और rarely useful है।

LENGTH, UPPER, और || (concatenation) जैसे string functions तीनों पर काम करते हैं।

Note: जब तक आपको truly एक length limit न चाहिए text इस्तेमाल करें।

उदाहरण: VARCHAR/TEXT

sql
CREATE TABLE tags (id INTEGER PRIMARY KEY, code VARCHAR(5), note TEXT);
INSERT INTO tags VALUES (1, 'a1', 'A short note'), (2, 'zz', 'Another, somewhat longer note');
SELECT code, LENGTH(note) AS note_length, UPPER(note) AS shout FROM tags;
SELECT code || ': ' || note AS combined FROM tags;

-- Output:
-- code | note_length | shout
-- a1 | 12 | A SHORT NOTE
-- zz | 29 | ANOTHER, SOMEWHAT LONGER NOTE
-- combined
-- a1: A short note
-- zz: Another, somewhat longer note
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. variable text के लिए char(n) इस्तेमाल करना
  2. यह मान लेना कि varchar(n) text से faster है
  3. यह भूल जाना कि || concatenation है
चैप्टर सारांश
  • text की कोई length limit नहीं
  • varchar(n) एक maximum enforce करता है
  • char(n) spaces से pad करता है
  • || strings concatenate करता है
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.