ruby on rails - Does Postgres hav an equivalent of 'mysqldump --where'? -


i'm working on rails project uses multi-tenanting gem milia. milia uses row-based tenanting, meaning every row in database has column named tenant_id determines data belongs to. use heroku , postgresql.

the database whole large, , while there times when want full production dump, more rather have data 1 tenant.

so i'd dump whole db, rows where tenant_id=x. mysqldump has where condition, can't find equivalent postgresql.

for example, if database this:

table members   tenant_id, id, name, sex   1, 1, joe, m   1, 2, sally, f   2, 3, bob, m    table jobs   tenant_id, id 1, 1 1, 2 2, 3 

and want dump tables tenant_id 1, expect dump containing following:

table members   tenant_id, id, name, sex   1, 1, joe, m   1, 2, sally, f    table jobs   tenant_id, id 1, 1 1, 2 

i'm not sure if best practice, can:

  1. create view of table rows want

create view tweets select * contents provider = 'twitter';

  1. create new table view

create table tweets_table select * tweets;

  1. in tab, dump new table

pg_dump -t tweets_table brainstream_development

  1. delete intermediate table

another option create view , copy psql (psql can import that):

create view tweets select * contents provider = 'twitter';

psql -d brainstream_development -a -t -c "select * tweets" > tweets.dump


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -