1 |
4428
|
aaronmk
|
#!/bin/sh
|
2 |
|
|
# Translates a MySQL data-only DB export to PostgreSQL
|
3 |
|
|
# The export must be created with:
|
4 |
|
|
# `--compatible=postgresql --add-locks=false --set-charset --no-create-info`
|
5 |
|
|
# Usage: self {input...|<input} >translated
|
6 |
|
|
|
7 |
|
|
sedEreFlag="$(test "$(uname)" = Darwin && echo E || echo r)"
|
8 |
|
|
|
9 |
|
|
sed () { "$(which sed)" -"$sedEreFlag" "$@";}
|
10 |
|
|
|
11 |
5886
|
aaronmk
|
echo 'SET standard_conforming_strings = off;'
|
12 |
5887
|
aaronmk
|
echo 'SET escape_string_warning = off;'
|
13 |
4428
|
aaronmk
|
sed \
|
14 |
8002
|
aaronmk
|
-e 's/([^\\](\\\\)*)\\0/$10/g' \
|
15 |
7536
|
aaronmk
|
-e "s/'0000-00-00( 00:00:00)?'/'-infinity'/g" \
|
16 |
7544
|
aaronmk
|
-e "s/('[[:digit:]]{4}-)00(-[[:digit:]]{2}')/\101\2/g" \
|
17 |
7543
|
aaronmk
|
-e "s/('[[:digit:]]{4}-[[:digit:]]{2}-)00(')/\101\2/g" \
|
18 |
4428
|
aaronmk
|
"$@"
|
19 |
8002
|
aaronmk
|
# \0 isn't allowed in UTF-8; note that \ is doubled for sed
|