You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
this method will allow you to specify the table you want to dump by creating a select query, that way you can only easily backup just a subset of the rows
defselect_dump(self, table, queries, outfile=None, pipes=None):
''' this uses a flow discussed here (in order to output only certain rows) http://dbaspot.com/postgresql/348627-pg_dump-t-give-where-condition.html '''ifnotoutfile: outfile=self._get_outfile(table)
ifisinstance(queries, basestring): queries= [queries]
ifnotqueries: raiseValueError('no queries to run')
ifnottable: raiseValueError('no table')
args= []
args+= [self.db]
temp_table='temp__{}'.format(table)
# could do print statements using \qecho# http://stackoverflow.com/questions/10663520run_queries= [
'DROP TABLE IF EXISTS {}'.format(temp_table),
'CREATE TABLE {} (LIKE {})'.format(temp_table, table),
]
# add all the queries that were passed in so our temp table gets populated with the data we want to keepforqinqueries: run_queries.append('INSERT INTO {} {}'.format(temp_table, q))
self._run_queries(run_queries)
ifnotpipes: pipes= []
pipes.append('sed -e "s/{}/{}/g"'.format(temp_table, table))
self.table_dump(table=temp_table, pipes=pipes, outfile=outfile)
self._run_queries(['DROP TABLE {}'.format(temp_table)])
returnTrue
The text was updated successfully, but these errors were encountered:
this method will allow you to specify the table you want to dump by creating a select query, that way you can only easily backup just a subset of the rows
The text was updated successfully, but these errors were encountered: