कई Rows INSERT करना
एक INSERT एक साथ कई rows add कर सकता है, जो कई separate statements से तेज़ है।
In this page:
Syntax
INSERT INTO table_name (column1, column2)
VALUES (value1, value2),
(value3, value4);
कई Rows Insert करना
Commas से separated कई parenthesised value lists provide करें। यह एक single statement है, इसलिए यह या तो सारी rows insert करता है या कोई नहीं।
बहुत बड़े loads के लिए COPY इस्तेमाल करें, जो INSERT से कहीं ज़्यादा तेज़ है।
PostgreSQL दूसरी table से copy करने के लिए INSERT ... SELECT भी support करता है।
Note:
COPY PostgreSQL में data bulk load करने का सबसे fast तरीका है।
उदाहरण: INSERT multiple rows
CREATE TABLE fruits (id INTEGER PRIMARY KEY, name TEXT, color TEXT);
INSERT INTO fruits (id, name, color) VALUES (1, 'apple', 'red'), (2, 'banana', 'yellow'), (3, 'grape', 'purple');
SELECT COUNT(*) AS total FROM fruits;
CREATE TABLE red_fruits AS SELECT * FROM fruits WHERE color = 'red';
SELECT name FROM red_fruits;
-- Output:
-- total
-- 3
-- name
-- apple
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. #}
आम गलतियां
- हज़ारों single-row inserts चलाना
- एक row में mismatched value counts
- बड़े loads को एक transaction में wrap न करना
चैप्टर सारांश
- कई VALUES tuples list करें
- एक single statement सब कुछ या कुछ नहीं है
- COPY सबसे तेज़ bulk data load करता है
- INSERT ... SELECT rows copy करता है
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: