Efficiently doing INSERT INTO...SELECT FROM in AR

I need to archive an entire set of rows from one table to another, in
effect, doing this SQL:

INSERT INTO table1
SELECT * FROM table2 WHERE blah…

Should I just do bare SQL or is there some “bulk insert” functionality
exposed in ActiveRecord for me to use?

Thanks,
Wes

Wes G. wrote:

Wes


Posted via http://www.ruby-forum.com/.

You could extract the table to a fixture, rename it, and load the
fixture.

_Kevin

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Wes G. wrote:

I need to archive an entire set of rows from one table to another, in
effect, doing this SQL:

INSERT INTO table1
SELECT * FROM table2 WHERE blah…

Should I just do bare SQL or is there some “bulk insert” functionality
exposed in ActiveRecord for me to use?

This functionality is in ActiveRecord::Extensions,
http://blogs.mktec.com/zdennis/pages/ARE
however it is NOT released. The current interface setup for this is…

Model.insert_into OtherModel, :conditions=>{ … }

I’m not 100% on the api for it yet, but your thoughts could concrete it
or I could implement it in another way. What db are you
using right now?

Zach

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFPoYBMyx0fW1d8G0RAihuAJ4xTgnWqj12afwfzGERjpV5iddwqACePpeb
54UWD35QDbIOuzyhHgSkHpc=
=y/O8
-----END PGP SIGNATURE-----

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Wes G. wrote:

I’m using SQL Server 2000 (gasp!).

I think the usage you propose is fine. I can’t think of anything fancy
that I’d need for my purposes.

Can you contact me privately at [email protected] and email me a few
different INSERT statements that you would hypothetically
use, I will make sure I add support for the MSSQL adapter for this
functionality.

I am going to use http://en.wikipedia.org/wiki/Insert_(SQL) as my
guide for conformance.

thanks,

Zach
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFPo8cMyx0fW1d8G0RAhM3AJ9ZKwxpbK+66CWYgRTGo7GPsJ7/PACfcTUo
tUv5xM35fTK19MeqRuU4IfE=
=vRdD
-----END PGP SIGNATURE-----

I’m using SQL Server 2000 (gasp!).

I think the usage you propose is fine. I can’t think of anything fancy
that I’d need for my purposes.

Wes

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs