How to import *.sql file to postgresql database

Started by Andre Lopesover 15 years ago8 messagesgeneral
Jump to latest
#1Andre Lopes
lopes80andre@gmail.com

Hi,

I have a DUMP file with INSERT's commands. I need to import this data to
postgresql database with the "psql" command.

How can I do this task?

Best Regards,

#2Szymon Guz
mabewlun@gmail.com
In reply to: Andre Lopes (#1)
Re: How to import *.sql file to postgresql database

2010/7/18 Andre Lopes <lopes80andre@gmail.com>

Hi,

I have a DUMP file with INSERT's commands. I need to import this data to
postgresql database with the "psql" command.

How can I do this task?

Best Regards,

Hi,
you can do that for example using the following command:

psql <database> < file.sql

where <datatabase> is the name of the database you use.

regards
Szymon Guz

#3Osvaldo Kussama
osvaldo.kussama@gmail.com
In reply to: Andre Lopes (#1)
Re: How to import *.sql file to postgresql database

2010/7/18 Andre Lopes <lopes80andre@gmail.com>:

Hi,

I have a DUMP file with INSERT's commands. I need to import this data to
postgresql database with the "psql" command.

How can I do this task?

Best Regards,

From manual [1]http://www.postgresql.org/docs/current/interactive/backup-dump.html#BACKUP-DUMP-RESTORE 24.1.1. Restoring the dump:
psql dbname < infile

Osvaldo
[1]: http://www.postgresql.org/docs/current/interactive/backup-dump.html#BACKUP-DUMP-RESTORE

#4Edoardo Panfili
edoardo@aspix.it
In reply to: Andre Lopes (#1)
Re: How to import *.sql file to postgresql database

On 18/07/10 22.06, Andre Lopes wrote:

Hi,

I have a DUMP file with INSERT's commands. I need to import this data to
postgresql database with the "psql" command.

How can I do this task?

I think

psql -U user_name database_name <dump_file

EDoardo

#5Andre Lopes
lopes80andre@gmail.com
In reply to: Szymon Guz (#2)
Re: How to import *.sql file to postgresql database

Thanks for the reply,

I have this error:

[quote]
ERROR: invalid byte sequence for encoding "UTF8": 0xff
HINT: This error can also happen if the byte sequence does not match the
encoding expected by the server, which is controlled by "client_encoding".
[/quote]

I have set the client encoding to LATIN1 like this,

[quote]
$psql <database>
database=> set client_encoding to "LATIN1";
SET
database=>\i /home/folder1/data.sql
[/quote]

Then I got this different error:

[quote]
psql:/home/folder1/data.sql:1: ERROR: syntax error at or near "ÿþ"
LINE 1: ÿþ-
^
[/quote]

How should I solve this problem?

Best Regards,

On Sun, Jul 18, 2010 at 9:10 PM, Szymon Guz <mabewlun@gmail.com> wrote:

Show quoted text

2010/7/18 Andre Lopes <lopes80andre@gmail.com>

Hi,

I have a DUMP file with INSERT's commands. I need to import this data to
postgresql database with the "psql" command.

How can I do this task?

Best Regards,

Hi,
you can do that for example using the following command:

psql <database> < file.sql

where <datatabase> is the name of the database you use.

regards
Szymon Guz

#6Andre Lopes
lopes80andre@gmail.com
In reply to: Edoardo Panfili (#4)
Re: How to import *.sql file to postgresql database

If I do this command gives me the same error:

[quote]
ERROR: invalid byte sequence for encoding "UTF8": 0xff
HINT: This error can also happen if the byte sequence does not match the
encoding expected by the server, which is controlled by "client_encoding".
[/quote]

What more can I do?

Best Regards,

On Sun, Jul 18, 2010 at 9:11 PM, Edoardo Panfili <edoardo@aspix.it> wrote:

Show quoted text

On 18/07/10 22.06, Andre Lopes wrote:

Hi,

I have a DUMP file with INSERT's commands. I need to import this data to
postgresql database with the "psql" command.

How can I do this task?

I think

psql -U user_name database_name <dump_file

EDoardo

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#7Osvaldo Kussama
osvaldo.kussama@gmail.com
In reply to: Andre Lopes (#6)
Re: How to import *.sql file to postgresql database

2010/7/18 Andre Lopes <lopes80andre@gmail.com>:

If I do this command gives me the same error:

[quote]
ERROR:  invalid byte sequence for encoding "UTF8": 0xff
HINT:  This error can also happen if the byte sequence does not match the
encoding expected by the server, which is controlled by "client_encoding".
[/quote]

What more can I do?

Best Regards,

On Sun, Jul 18, 2010 at 9:11 PM, Edoardo Panfili <edoardo@aspix.it> wrote:

On 18/07/10 22.06, Andre Lopes wrote:

Hi,

I have a DUMP file with INSERT's commands. I need to import this data to
postgresql database with the "psql" command.

How can I do this task?

I think

psql -U user_name database_name <dump_file

EDoardo

A BOM (Byte Order Mark) case?
http://en.wikipedia.org/wiki/Byte_order_mark

http://archives.postgresql.org/pgsql-sql/2010-06/msg00065.php

Osvaldo

#8Rory Campbell-Lange
rory@campbell-lange.net
In reply to: Andre Lopes (#6)
Re: How to import *.sql file to postgresql database

On 18/07/10, Andre Lopes (lopes80andre@gmail.com) wrote:

If I do this command gives me the same error:

[quote]
ERROR: invalid byte sequence for encoding "UTF8": 0xff
HINT: This error can also happen if the byte sequence does not match the
encoding expected by the server, which is controlled by "client_encoding".
[/quote]

What more can I do?

You still have an encoding/decoding issue, so your load sequence is not
occurring under a LATIN1 encoding in this instance. You may want to look
at iconv to convert your source to a more desirable encoding.

However, from your emails it may be that your file is not a normal text
file dump, but a dump file made with the -Fc flags. Please read the
pg_dump manpage, and, if after inspection of the file itself it proves
to be in the custom, compressed format produced by -Fc, you should use
the pg_restore command to restore from this file.

--
Rory Campbell-Lange
rory@campbell-lange.net