title: SQL: insert multiple rows at once
body: <p>I have an array of values like this (<code>restaurant_id</code> is not a primary key):</p>
  
  <pre><code>[
  {restaurant_id:1, day_of_week:0, from_time: "12:00", to_time: "14:00", is_open:false },
  {restaurant_id:1, day_of_week:1, from_time: "12:00", to_time: "14:00", is_open:true },
  {restaurant_id:1, day_of_week:2, from_time: "12:00", to_time: "14:00", is_open:true },
  ...
  ]
  </code></pre>
  
  <p>One entry for every day.</p>
  
  <p>I would like to save each of them as a new row in a <code>PostgreSQL</code> database.</p>
  
  <p>I have this query for one insert:</p>
  
  <pre><code>INSERT INTO schedules (restaurant_id, day_of_week, from_time, to_time, is_open) VALUES ($1, $2, $3, $4, $5) RETURNING schedules;
  </code></pre>
  
  <p>Should I do 7 <code>INSERT</code> statements or can I loop and save all in one statement?</p>
  
  <p>What would be the query with the loop?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>So I could do in one query something like this, as suggested:</p>
  
  <pre><code> VALUES (?, ?, ?, ? ?),
          (?, ?, ?, ? ?),
          (?, ?, ?, ? ?),
          (?, ?, ?, ? ?),
          (?, ?, ?, ? ?),
          (?, ?, ?, ? ?),
          (?, ?, ?, ? ?)
  </code></pre>
  
  <p>but is there a better way of doing this?</p>