1
|
#!/bin/bash -e
|
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
|
. "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"/../lib/sh/util.sh
|
8
|
|
9
|
echo 'SET standard_conforming_strings = off;'
|
10
|
echo 'SET escape_string_warning = off;'
|
11
|
sed \
|
12
|
-e 's/([^\\](\\\\)*)\\0/$10/g' \
|
13
|
-e "s/'0000-00-00( 00:00:00)?'/'-infinity'/g" \
|
14
|
-e "s/('[[:digit:]]{4}-)00(-[[:digit:]]{2}')/\101\2/g" \
|
15
|
-e "s/('[[:digit:]]{4}-[[:digit:]]{2}-)00(')/\101\2/g" \
|
16
|
"$@"
|
17
|
# \0 isn't allowed in UTF-8; note that \ is doubled for sed
|