← Back to PostgreSQL Course | Chapter 4: Inserting & Modifying Data | Lesson 2 of 7

कई Rows INSERT करना

एक INSERT एक साथ कई rows add कर सकता है, जो कई separate statements से तेज़ है।
Syntax
sql
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

sql
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
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. हज़ारों single-row inserts चलाना
  2. एक row में mismatched value counts
  3. बड़े 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:

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.