Skip to content
    geeksforgeeks
    • Interview Prep
      • DSA
      • Interview Corner
      • Aptitude & Reasoning
      • Practice Coding Problems
      • All Courses
    • Tutorials
      • Python
      • Java
      • ML & Data Science
      • Programming Languages
      • Web Development
      • CS Subjects
      • DevOps
      • Software and Tools
      • School Learning
    • Tracks
      • Languages
        • Python
        • C
        • C++
        • Java
        • Advanced Java
        • SQL
        • JavaScript
        • C#
      • Interview Preparation
        • GfG 160
        • GfG 360
        • System Design
        • Core Subjects
        • Interview Questions
        • Interview Puzzles
        • Aptitude and Reasoning
        • Product Management
        • Computer Organisation and Architecture
      • Data Science
        • Python
        • Data Analytics
        • Complete Data Science
        • Gen AI
        • Agentic AI
      • Dev Skills
        • Full-Stack Web Dev
        • DevOps
        • Software Testing
        • CyberSecurity
        • NextJS
        • Git
      • Tools
        • Computer Fundamentals
        • AI Tools
        • MS Excel & Google Sheets
        • MS Word & Google Docs
      • Maths
        • Maths For Computer Science
        • Engineering Mathematics
        • School Maths
    • DSA
    • Practice Problems
    • C
    • C++
    • Java
    • Python
    • JavaScript
    • Data Science
    • Machine Learning
    • Courses
    • Linux
    • DevOps
    • SQL
    • Web Development
    • System Design
    • Aptitude
    Open In App

    PostgreSQL - Insert Multiple Values in Various Rows

    Last Updated : 23 Jul, 2025
    Comments
    Improve
    Suggest changes
    2 Likes
    Like
    Report

    PostgreSQL, one of the most popular relational database management systems (RDBMS), is widely used for storing structured data in a tabular format, much like MySQL. In relational databases, data is stored in tables where each row represents a record and each column represents an attribute. One of the most common tasks in database management is inserting data into tables. In this article, we will explore how to efficiently insert multiple rows into a PostgreSQL database using the INSERT statement.

    INSERT Statement in PostgreSQL

    In PostgreSQL, the INSERT statement is typically used to add new rows to a table. However, when you need to insert multiple rows at once, PostgreSQL offers a more optimized approach than running multiple individual INSERT statements. This method can save you time and reduce overhead, especially when dealing with large datasets.

    Syntax :

    ##When specifying Column Names
    INSERT INTO tableName (col1, col2) VALUES (value,value),(value,value),(value,value);
    
    ## When not specifying Column Names
    INSERT INTO tableName VALUES (value,value),(value,value),(value,value);

    Approach:

    1. Our database name is geeksforgeeks and the table name is gfg at the beginning there is no data inside the table. For selecting the database we will use query  \c databaseName.
    2. For checking the data inside the table we will use query select *from tableName.
    3. Now for inserting values, we will use the table name and the column names and the records to be inserted will be separated by comma("'").
    4. The query will be Insert into tableName (col1, col2) values (value,value),(value,value),(value,value).
    5. If you want to insert without the column names then the query will be a different one than the above query.
    6. Insert into tableName  values (value,value),(value,value),(value,value) . But one thing should be remembered here that in this case, the order of the values being inserted should be the same as that of in the database and all the mandatory columns must be inserted.
    7. Now again we will check for records inside the table using select*from tableName.

    Examples of Inserting Multiple Values in Various Rows

    Let us look into some of the examples of inserting multiple values in rows in PostgreSQL.

    Example 1: Inserting Multiple Rows with Specified Column Names

    In this example, we first selected the database using the \c geeksforgeeks command, and then we looked into the database table records then we inserted the multiples record inside the table then again look inside the database tables. The steps followed are to select the database and then look into the table records then insert multiple values and then again look into the table records.

    PostgreSQL - Insert Multiple Values in Various RowsPostgreSQL - Insert Multiple Values in Various Rows

    Example 2: Inserting Multiple Rows Without Specifying Column Names

    Here in this example, we will insert the rows without using the column names but one thing to note about this approach is if you are not giving the column names the order of values being inserted will be the same as that of in the table and all the mandatory columns must be filled in the table otherwise there will be an exception. After inserting the data we will again look into the database table.

    PostgreSQL - Insert Multiple Values in Various RowsPostgreSQL - Insert Multiple Values in Various Rows
    Create Quiz

    R

    rajatagrawal5
    Improve

    R

    rajatagrawal5
    Improve
    Article Tags :
    • PostgreSQL
    • postgreSQL-managing-table

    Explore

      Basics

      What is PostgreSQL - Introduction

      2 min read

      Install PostgreSQL on Windows

      2 min read

      Install PostgreSQL on Mac

      3 min read

      Database Operations

      PostgreSQL - Create Database

      5 min read

      PostgreSQL - Loading a Database

      3 min read

      PostgreSQL ALTER DATABASE

      3 min read

      PostgreSQL - Rename Database

      4 min read

      PostgreSQL - Show Databases

      3 min read

      Data Types

      PostgreSQL - Data Types

      5 min read

      PostgreSQL - Boolean Data Type

      4 min read

      PostgreSQL - CHAR Data Type

      5 min read

      PostgreSQL - VARCHAR Data Type

      3 min read

      PostgreSQL - NUMERIC Data Type

      5 min read

      PostgreSQL - Date Data Type

      4 min read

      PostgreSQL - TIME Data Type

      4 min read

      PostgreSQL - JSON Data Type

      4 min read

      PostgreSQL - CREATE DOMAIN

      3 min read

      Querying Tables

      PostgreSQL - SELECT

      3 min read

      PostgreSQL - ORDER BY clause

      2 min read

      PostgreSQL - WHERE clause

      6 min read

      PostgreSQL FETCH Clause

      4 min read

      PostgreSQL - IN operator

      4 min read

      PostgreSQL - HAVING clause

      4 min read

      PostgreSQL - GROUP BY clause

      4 min read

      PostgreSQL - LIKE operator

      5 min read

      PostgreSQL - BETWEEN Operator

      3 min read

      Table Operations

      PostgreSQL - CREATE TABLE

      5 min read

      PostgreSQL - SELECT INTO

      4 min read

      PostgreSQL - CREATE SEQUENCE

      4 min read

      PostgreSQL - ALTER TABLE

      6 min read

      PostgreSQL - ADD COLUMN

      4 min read

      PostgreSQL - DROP COLUMN

      2 min read

      PostgreSQL - Rename Table

      2 min read

      PostgreSQL - DROP TABLE

      5 min read

      PostgreSQL - TRUNCATE TABLE

      4 min read

      PostgreSQL - Copy a Table

      3 min read

      PostgreSQL - Comparing Tables

      3 min read

      PostgreSQL - Show Tables

      4 min read

      Modifying Data

      PostgreSQL - INSERT

      4 min read

      PostgreSQL - Insert Multiple Values in Various Rows

      3 min read

      PostgreSQL UPDATE Statement

      5 min read

      PostgreSQL - DELETE

      4 min read

      PostgreSQL - Upsert

      4 min read

      Conditionals

      PostgreSQL - CASE

      3 min read

      PostgreSQL COALESCE

      5 min read

      PostgreSQL - NULLIF() Function

      4 min read

      PostgreSQL - CAST

      3 min read

      Control Flow

      PostgreSQL - IF Statement

      5 min read

      PostgreSQL - CASE Statement

      4 min read

      PostgreSQL - Loop Statement

      3 min read

      PostgreSQL - While Loops

      4 min read

      PostgreSQL - Exit Statement

      3 min read

      PostgreSQL - Continue

      3 min read

      Transactions & Constraints

      PostgreSQL - Transactions

      4 min read

      PostgreSQL - COMMIT

      4 min read

      PostgreSQL - Primary Key

      4 min read

      PostgreSQL - Foreign Key

      5 min read

      PostgreSQL - CHECK Constraint

      2 min read

      PostgreSQL - UNIQUE Constraint

      3 min read

      PostgreSQL - NOT NULL Constraint

      3 min read

      JOINS & Schemas

      PostgreSQL - Joins

      5 min read

      PostgreSQL - LEFT JOIN

      5 min read

      PostgreSQL - INNER JOIN

      2 min read

      PostgreSQL - FULL OUTER JOIN

      4 min read

      PostgreSQL - SELF JOIN

      4 min read

      PostgreSQL - Schema

      5 min read

      PostgreSQL - CREATE SCHEMA

      5 min read

      PostgreSQL - DROP SCHEMA

      4 min read

      PostgreSQL - ALTER SCHEMA

      3 min read
    top_of_element && top_of_screen < bottom_of_element) || (bottom_of_screen > articleRecommendedTop && top_of_screen < articleRecommendedBottom) || (top_of_screen > articleRecommendedBottom)) { if (!isfollowingApiCall) { isfollowingApiCall = true; setTimeout(function(){ if (loginData && loginData.isLoggedIn) { if (loginData.userName !== $('#followAuthor').val()) { is_following(); } else { $('.profileCard-profile-picture').css('background-color', '#E7E7E7'); } } else { $('.follow-btn').removeClass('hideIt'); } }, 3000); } } }); } $(".accordion-header").click(function() { var arrowIcon = $(this).find('.bottom-arrow-icon'); arrowIcon.toggleClass('rotate180'); }); }); window.isReportArticle = false; function report_article(){ if (!loginData || !loginData.isLoggedIn) { const loginModalButton = $('.login-modal-btn') if (loginModalButton.length) { loginModalButton.click(); } return; } if(!window.isReportArticle){ //to add loader $('.report-loader').addClass('spinner'); jQuery('#report_modal_content').load(gfgSiteUrl+'wp-content/themes/iconic-one/report-modal.php', { PRACTICE_API_URL: practiceAPIURL, PRACTICE_URL:practiceURL },function(responseTxt, statusTxt, xhr){ if(statusTxt == "error"){ alert("Error: " + xhr.status + ": " + xhr.statusText); } }); }else{ window.scrollTo({ top: 0, behavior: 'smooth' }); $("#report_modal_content").show(); } } function closeShareModal() { const shareOption = document.querySelector('[data-gfg-action="share-article"]'); shareOption.classList.remove("hover_share_menu"); let shareModal = document.querySelector(".hover__share-modal-container"); shareModal && shareModal.remove(); } function openShareModal() { closeShareModal(); // Remove existing modal if any let shareModal = document.querySelector(".three_dot_dropdown_share"); shareModal.appendChild(Object.assign(document.createElement("div"), { className: "hover__share-modal-container" })); document.querySelector(".hover__share-modal-container").append( Object.assign(document.createElement('div'), { className: "share__modal" }), ); document.querySelector(".share__modal").append(Object.assign(document.createElement('h1'), { className: "share__modal-heading" }, { textContent: "Share to" })); const socialOptions = ["LinkedIn", "WhatsApp","Twitter", "Copy Link"]; socialOptions.forEach((socialOption) => { const socialContainer = Object.assign(document.createElement('div'), { className: "social__container" }); const icon = Object.assign(document.createElement("div"), { className: `share__icon share__${socialOption.split(" ").join("")}-icon` }); const socialText = Object.assign(document.createElement("span"), { className: "share__option-text" }, { textContent: `${socialOption}` }); const shareLink = (socialOption === "Copy Link") ? Object.assign(document.createElement('div'), { role: "button", className: "link-container CopyLink" }) : Object.assign(document.createElement('a'), { className: "link-container" }); if (socialOption === "LinkedIn") { shareLink.setAttribute('href', `https://www.linkedin.com/sharing/share-offsite/?url=${window.location.href}`); shareLink.setAttribute('target', '_blank'); } if (socialOption === "WhatsApp") { shareLink.setAttribute('href', `https://api.whatsapp.com/send?text=${window.location.href}`); shareLink.setAttribute('target', "_blank"); } if (socialOption === "Twitter") { shareLink.setAttribute('href', `https://twitter.com/intent/tweet?url=${window.location.href}`); shareLink.setAttribute('target', "_blank"); } shareLink.append(icon, socialText); socialContainer.append(shareLink); document.querySelector(".share__modal").appendChild(socialContainer); //adding copy url functionality if(socialOption === "Copy Link") { shareLink.addEventListener("click", function() { var tempInput = document.createElement("input"); tempInput.value = window.location.href; document.body.appendChild(tempInput); tempInput.select(); tempInput.setSelectionRange(0, 99999); // For mobile devices document.execCommand('copy'); document.body.removeChild(tempInput); this.querySelector(".share__option-text").textContent = "Copied" }) } }); // document.querySelector(".hover__share-modal-container").addEventListener("mouseover", () => document.querySelector('[data-gfg-action="share-article"]').classList.add("hover_share_menu")); } function toggleLikeElementVisibility(selector, show) { document.querySelector(`.${selector}`).style.display = show ? "block" : "none"; } function closeKebabMenu(){ document.getElementById("myDropdown").classList.toggle("show"); }
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Campus Training Program
  • Explore
  • POTD
  • Job-A-Thon
  • Blogs
  • Nation Skill Up
  • Tutorials
  • Programming Languages
  • DSA
  • Web Technology
  • AI, ML & Data Science
  • DevOps
  • CS Core Subjects
  • Interview Preparation
  • Software and Tools
  • Courses
  • ML and Data Science
  • DSA and Placements
  • Web Development
  • Programming Languages
  • DevOps & Cloud
  • GATE
  • Trending Technologies
  • Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
  • Preparation Corner
  • Interview Corner
  • Aptitude
  • Puzzles
  • GfG 160
  • System Design
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.
See More

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences