# Generate SQL-Statement from Model.save()

**URL:** <https://www.ruby-forum.com/t/generate-sql-statement-from-model-save/126559>\
**Category:** Rails\
**Created:** [January 19, 2008, 3:47pm UTC](https://www.ruby-forum.com/t/generate-sql-statement-from-model-save/126559 "2008-01-19T15:47:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![LpLpLp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/bc8723/32.png) [@LpLpLp](https://www.ruby-forum.com/u/LpLpLp)\
**Post date:** [January 19, 2008, 3:47pm UTC](https://www.ruby-forum.com/t/generate-sql-statement-from-model-save/126559/1 "2008-01-19T15:47:55Z")

</div>

Hello!

Im a rails newbie, i like rails very much, but now I have a problem:

I want to generate in one action about 3000 sql statements  
(mailtemplate that becomes generateted to a mail (with personal  
salutation,…)).

I tried it with:

x=0  
while x \< 300  
q = mail.new(params…)  
q.save()  
end

but thats muuuuch toooo slow… Is there a chance to get the  
generated sql statement back and execute it afterwards with only one  
sql-execution statement?

thanks!

---

<div class="post-metadata">

**Author:** ![LpLpLp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/bc8723/32.png) [@LpLpLp](https://www.ruby-forum.com/u/LpLpLp)\
**Post date:** [January 19, 2008, 4:20pm UTC](https://www.ruby-forum.com/t/generate-sql-statement-from-model-save/126559/2 "2008-01-19T16:20:19Z")

</div>

On Jan 19, 2008, at 8:47 AM, Lp wrote:

> 

While it’s not exactly the same as you are looking to do, there was a  
discussion of something similar in this thread

[http://www.ruby-forum.com/topic/136898](http://www.ruby-forum.com/topic/136898)

If you have the patience to get to the end (and it’s really not that  
long), there is an example of extending ActiveRecord to support  
return the generated SQL. It probably wouldn’t be too hard to do  
what you are looking to do.

Peace,  
Phillip
