VARCHAR और TEXT
text किसी भी length की strings store करता है जबकि varchar(n) एक maximum length enforce करता है।
In this page:
Syntax
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
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
Login to try C/C++/Java/PHP code in the editor
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. #}
आम गलतियां
- variable text के लिए char(n) इस्तेमाल करना
- यह मान लेना कि varchar(n) text से faster है
- यह भूल जाना कि || 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: