# Insert into database with one instruction

**URL:** <https://www.ruby-forum.com/t/insert-into-database-with-one-instruction/121225>\
**Category:** Rails\
**Created:** [November 25, 2007, 5:58pm UTC](https://www.ruby-forum.com/t/insert-into-database-with-one-instruction/121225 "2007-11-25T17:58:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/49beb7/32.png) [@jney](https://www.ruby-forum.com/u/jney)\
**Post date:** [November 25, 2007, 5:58pm UTC](https://www.ruby-forum.com/t/insert-into-database-with-one-instruction/121225/1 "2007-11-25T17:58:05Z")

</div>

hello, i’d like to insert into a table with a rails function several  
records and avoid a loop with Object.create. Something corresponding  
to SQL instruction like it :

INSERT INTO animals(id, value)  
VALUES(1, ‘dog’), (2, ‘cat’), (3, 'bird);

is it possible to do it with a create or another function? i’m looking  
for it but don’t find anything about it.

---

<div class="post-metadata">

**Author:** ![jney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/49beb7/32.png) [@jney](https://www.ruby-forum.com/u/jney)\
**Post date:** [November 25, 2007, 6:54pm UTC](https://www.ruby-forum.com/t/insert-into-database-with-one-instruction/121225/2 "2007-11-25T18:54:52Z")

</div>

On 25 Nov 2007, at 16:57, Jean-Sébastien wrote:

> hello, i’d like to insert into a table with a rails function several  
> records and avoid a loop with Object.create. Something corresponding  
> to SQL instruction like it :
> 
> INSERT INTO animals(id, value)  
> VALUES(1, ‘dog’), (2, ‘cat’), (3, 'bird);
> 
> is it possible to do it with a create or another function? i’m looking  
> for it but don’t find anything about it.

You’re going to have to do this by hand (ie connection.execute ‘…’).

Fred
