dump data from postgresql for use in phpunit with sqlite
I want to dump data from my postgresql database and use it as a base data set for phpunit (where I use sqlite in memory).
is it possible?
the closest i get is:
pg_dump -a -d -UmyUser myDatabase > /tmp/somedata.sql
grep INSERT /tmp/somedata.sql > /tmp/onlyinserts.sql
but the开发者_开发知识库 problem i got is that the inserts are not ordered, e.g. first i get some inserts which references to data in other tables which has not been inserted yet....
May be you shoule add -- inserts parameter to dump your database as insert statement , for example
pg_dump -h host_ip -U username --inserts db_name > db_name.txt
--About the "inserts" parameter -d, --inserts dump data as INSERT, rather than COPY, commands
ok, after trying around I got this hack to work, far from ideal, but works for the data set I got:
pg_dump -a -D -UmyUser myDatabse > /tmp/dbstuff.sql
cat /tmp/dbstuff.sql |grep -v 'SET' |grep -v 'SELECT' > t2.sql
sed 's/true/1/g' < t2.sql > tt
sed 's/false/0/g' < tt > testdb_content.sql
so it was actually not the ordering that was bothering it, it was keywords it didnt know (the error message was not giving that away though...)
精彩评论