Last active
January 7, 2018 06:03
-
-
Save MasonM/1023ebc74cc5b0b0cd9d5cce8e6ae11e to your computer and use it in GitHub Desktop.
pg_dump_filter_and_separate.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
pg_dump --column-inserts | php -B '$dir = "sql"; $cur_table = null;' -R ' | |
if (preg_match("/^(INSERT INTO (\w+) \([^)]*\) VALUES )(.*);$/", $argn, $matches)) { | |
$str = ($cur_table !== $matches[2]) ? $matches[1] : ","; | |
$cur_table = $matches[2]; | |
file_put_contents("$dir/$cur_table.sql", "{$str}\n\t{$matches[3]}", FILE_APPEND); | |
}' -E 'foreach(glob("$dir/*.sql") as $f) file_put_contents($f, ";", FILE_APPEND);' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment