Обсуждение: Importing Mangled SQL File via psql

Поиск
Список
Период
Сортировка

Importing Mangled SQL File via psql

От
APseudoUtopia
Дата:
Hey list,

I have a dump of a table from a mysql database. I spent the last two
days running search-and-replace regexes and other such formatting
changes in order to get it loadable into PostgreSQL. I finally got to
what seemed like the end of the process, when this happened as I tried
to load it:

db_user@main_db => BEGIN;
BEGIN
Time: 0.243 ms
db_user@main_db *=> \i data.sql
INSERT 0 431
Time: 679.312 ms
INSERT 0 323
Time: 193.857 ms
Query buffer reset (cleared).
psql:data.sql:3: invalid command \n
db_user@main_db *=> ROLLBACK;
ROLLBACK
Time: 0.458 ms

The file does contain quite a bit of \r\n's in them for newlines
inside VARCHAR and TEXT columns, but I thought they would be converted
into actual newlines as I import it, not the actual character strings
"\n" and "\r". I know that \r is the psql command to clear the query
buffer, which is why that message is showing up in the above log. Does
anyone recommend anything to solve this problem? Should I just replace
\r\n with a space or an actual line break in the sql file itself?

Thanks.

Re: Importing Mangled SQL File via psql

От
Tom Lane
Дата:
APseudoUtopia <apseudoutopia@gmail.com> writes:
> The file does contain quite a bit of \r\n's in them for newlines
> inside VARCHAR and TEXT columns, but I thought they would be converted
> into actual newlines as I import it, not the actual character strings
> "\n" and "\r".

If they're inside quoted literals or COPY data, yes; but it looks like
you have one instance that isn't.

            regards, tom lane