I just started using Postgres and I'm trying to create a sample db to understand its functions, looking around, I found some scripts in pgfoundry.org. I understand the commands, since I previously used both Oracle and MS-SQL, but all the scripts I'm running return errors when they reach the "COPY FROM" instruction. More precisely, the error is thrown at the first element that should be inserted in the given table.
I've tried running the scripts both as queries and as pgScripts, but in both ways I'm getting an error at the first row after the COPY FROM.
I'm using pgAdminIII and I used StackBuilder to install PostgreSQL 9.2.4.1 as a DB Driver. May I be missing some basic configuration that's preventing me from running this command, or I just did not understand they way it works?
EDIT:
The error is:
ERROR: syntax error at or near "7"
LINE 5600: 7 4 13 37 2012年03月10日 16:41:43.797787 2012年03月10日 16:41:43.797...
^
********** Error **********
ERROR: syntax error at or near "7"
SQL status: 42601
Char: 140891`
where the text is:
COPY action_abilitations (id, group_action_id, partecipation_role_id, group_id, created_at, updated_at) FROM stdin;
7 4 13 37 2012年03月10日 16:41:43.797787 2012年03月10日 16:41:43.797787`
1 Answer 1
pgScript is a local script extension of pgAdmin, which you most probably do not want here.
pgAdmin is a GUI, not a console application - there is no stdin
you could easily use. If you need stdin
to stream your content, use psql, which is a console application - with the \copy
meta-command of psql.
If you have a file (which you obviously do), just use SQL COPY
from pgAdmin:
COPY action_abilitations (id, group_action_id, ...)
FROM 'C:\Users\usernexus\Desktop\database05-12-2012.sql';
The file needs to be readable to the postgres
system user.
More info in this closely related request to the pgAdmin support list.
-
ok, do you mean I should run the script with a line like:
psql postgres -p 5432 -f C:\Users\usernexus\Desktop\database05-12-2012.sql
? Also, I'm just trying everything locally, I just installed pgAdmin on my laptop.Eugenio Laghi– Eugenio Laghi2013年04月26日 19:06:50 +00:00Commented Apr 26, 2013 at 19:06 -
1@EugenioLaghi: Not exactly.
psql -f
would execute an SQL script file. You seem to deal with a data file. I updated my answer.Erwin Brandstetter– Erwin Brandstetter2013年04月26日 20:21:27 +00:00Commented Apr 26, 2013 at 20:21 -
THANKS! At the beginning I was trying to execute a script, but now at least I figured out how to COPY data from a file! Yesterday evening I was just too tired to understand.. :)Eugenio Laghi– Eugenio Laghi2013年04月27日 10:42:09 +00:00Commented Apr 27, 2013 at 10:42
-
How do you I make sure that the postgres user can read the file. I made that happen for the txt file, even for my desktop (where the file is located), but the permission is still denied.user29363– user293632013年10月14日 13:31:35 +00:00Commented Oct 14, 2013 at 13:31
-
@Geo: Please start a new question including Postgres version, OS, where the file lies, the verbatim command you used and more if relevant ...Erwin Brandstetter– Erwin Brandstetter2013年10月14日 17:00:53 +00:00Commented Oct 14, 2013 at 17:00
SET lc_messages = C
Just run it in your SQL editor window, which "contains" a session.SET lc_messages = 'C'
.