Обсуждение: How to import *.sql file to postgresql database

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

How to import *.sql file to postgresql database

От
Andre Lopes
Дата:
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,

Re: How to import *.sql file to postgresql database

От
Szymon Guz
Дата:


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

Re: How to import *.sql file to postgresql database

От
Osvaldo Kussama
Дата:
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] 24.1.1. Restoring the dump:
psql dbname < infile

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

Re: How to import *.sql file to postgresql database

От
Andre Lopes
Дата:
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:


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

Re: How to import *.sql file to postgresql database

От
Edoardo Panfili
Дата:
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

Re: How to import *.sql file to postgresql database

От
Andre Lopes
Дата:
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

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

Re: How to import *.sql file to postgresql database

От
Osvaldo Kussama
Дата:
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

Re: How to import *.sql file to postgresql database

От
Rory Campbell-Lange
Дата:
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