if that were me, I'd probably use the ORM to just copy the tables and
rows I care about to a blank database, then use mysqldump on that
database.  dumping is hard, there's lots of formatting and escaping
issues that you'd otherwise need to work out on your own.



On 01/12/2016 04:17 PM, Sam Raker wrote:
> I want to dump a subsection of a database. I've found this
> <http://docs.sqlalchemy.org/en/rel_1_0/faq/metadata_schema.html#how-can-i-get-the-create-table-drop-table-output-as-a-string>
>  in
> the SQLA documentation to dump schemata, and found this SO answer
> <http://stackoverflow.com/questions/135835/limiting-the-number-of-records-from-mysqldump>
>  to
> indiscriminately dump the first n rows of one or more tables, but that
> doesn't guarantee that all related objects will 'come along'--there's a
> decent chance, for example, that relevant rows in many-to-many tables
> won't get included. Is there a way to do something like (using
> SQLAlchemy 1.0.9 with MySQL)
> 
> |
> my_objects =session.query(MyTable).filter(MyTable.created_at
>>=some_date).all()
> withopen('my_objects_dump.sql','w')asdump_file:
>     do_some_magic_with(my_objects,dump_file)
> 
> ...
> 
> 
> $ mysql my_database <my_objects_dump.sql
> |
> 
> and then have my_database contain my_objects AND their related objects?
> I'm perfectly happy wrangling schemata and data separately.
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to sqlalchemy+unsubscr...@googlegroups.com
> <mailto:sqlalchemy+unsubscr...@googlegroups.com>.
> To post to this group, send email to sqlalchemy@googlegroups.com
> <mailto:sqlalchemy@googlegroups.com>.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to