Postgresql Copy Syntax error - postgresql

While running copy command on Postgresql I am getting SQL syntax error. Please find below command.
COPY analyte (id, name, normal_max, normal_min, unit_of_measure, version, category, data_type) FROM stdin;
16 Cholesterol - HDL (Good) \N 40 mg/dl 0 3 9
\.
Error
ERROR: syntax error at or near "16"
LINE 2: 16 Cholesterol - HDL (Good) \N 40 mg/dl 0 3 9
^
********** Error **********
ERROR: syntax error at or near "16"
SQL state: 42601
Character: 109

This script format - a COPY FROM stdin statement followed by a stream of data - is designed to be executed by psql. Most other tools (e.g. pgAdmin) won't know what to do with it.
I'm guessing this script came from pg_dump. If you want something which you can run without psql, you can use pg_dump --column-inserts to dump the table as a series of INSERT statements instead of a COPY.

Related

Copy from HDD to table

I'm attempting to copy files from C: drive to a table in postgresql but there is a syntax error that I cannot resolve.
COPY address_alias_type_aut
C:\GNAF\Authority Code\Authority_Code_ADDRESS_ALIAS_TYPE_AUT_psv.csv' DELIMITER '|' CSV HEADER;
But it will not run:
ERROR: syntax error at or near "C"
LINE 3: C:\GNAF\Authority Code\Authority_Code_ADDRESS_ALIAS_TYPE_AUT...
^
SQL state: 42601
Character: 30
I've searched this forum and found reference to escape backslashes and slashes but neither works as per:
ERROR: syntax error at or near "C"
LINE 1: COPY address_alias_type_aut from C:\\GNAF\\Authority Code\\A...
^
SQL state: 42601
Character: 34
and
ERROR: syntax error at or near "C"
LINE 1: COPY address_alias_type_aut from C://GNAF//Authority Code//A...
^
SQL state: 42601
Character: 34
COPY address_alias_type_aut from C:\\GNAF\\Authority Code\\Authority_Code_ADDRESS_ALIAS_TYPE_AUT_psv.csv' DELIMITER '|' CSV HEADER;
COPY address_type_aut from C:\\GNAF\\Authority Code\\Authority_Code_ADDRESS_TYPE_AUT_psv.csv' DELIMITER '|' CSV HEADER;
Results for each version - single forward or backslash, and double forward or backslash is the same - error at C

Running Spatial Queries in PostGIS 2.1.3 and Postgresql 9.3 in Windows 7

I installed PostGreSql 9.3 ( PgAdmin 3 GUI) and PostGIS 2.1.3 (http://www.enterprisedb.com/products-services-training/pgdownload#windows) for Windows 7 64 bit.
After installing it, I downloaded the Sql files for country database (http://www.spatial.cs.umn.edu/Book/labs/vania/spatialQueries.html) and tried to execute the commands in Country.sql
in the Sql Builder and stuck at the following error:
NOTICE: SRID value -1 converted to the officially unknown SRID value 0
CONTEXT: SQL statement "SELECT AddGeometryColumn('',$1,$2,$3,$4,$5,$6,$7)"
PL/pgSQL function addgeometrycolumn(character varying,character varying,character varying,integer,character varying,integer,boolean) line 5 at SQL statement
ERROR: function geometryfromtext(unknown, integer) does not exist
LINE 4: ...3000.0000','Dollar','USD','N','5','United States',GeometryFr...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
********** Error **********
ERROR: function geometryfromtext(unknown, integer) does not exist
SQL state: 42883
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
Character: 769
I can't get this error resolved. Please help me out.

syntax error for copy command in postgresql

I used the command:
COPY studentapp_deg_course_cat(degree_code, specialization, category_level1, category_level2, category_level3, min_credit, max_credit, primary)
FROM '/home/abhishek/Downloads/courses.csv'
USING DELIMITERS ';'
and i am getting the following error:
ERROR: syntax error at or near "COPY" LINE 1: COPY studentapp_deg_course_cat(degree_code, specialization,...
^
********** Error **********
ERROR: syntax error at or near "COPY" SQL state: 42601 Character: 1
I would like to know the error in my code
Valid COPY syntax for version 9.1 on Linux should be:
COPY studentapp_deg_course_cat(degree_code, specialization, category_level1,
category_level2, category_level3, min_credit, max_credit, "primary")
FROM '/home/abhishek/Downloads/courses.csv'
WITH (DELIMITER ';')
WITH, not USING.
DELIMITER instead of DELIMITERS.
And do not use primary as column name. It's a reserved word.

Syntax error postgresql

I have a syntax error on Postgresql:
The error :
ERROR: syntax error at or near "\"
LINE 19066: \.
^
********** Erreur **********
ERROR: syntax error at or near "\"
État SQL :42601
Caractère : 678313
And the offending line
COPY accesslog (aid, sid, title, path, url, hostname, uid, timer, "timestamp") FROM stdin;
\.
Do you have an idea what's wrong?
PgAdmin-III doesn't support interactive line-by-line COPY. Use psql.
That said, I think you are trying to COPY data FROM the server, not to it. If that's the case, either use COPY ... TO 'some-file-name' (a path relative to the database server), use pg_dump, or use psql with \copy.

Error when trying to restore backup

This line(518):
COPY wp_commentmeta (meta_id, comment_id, meta_key, meta_value) FROM stdin;
\.
is giving this error:
[ERROR ] 518.0: syntax error, unexpected character
What is this?
I have done backup before with this database, and now I'm just trying to restore all the tables back to the database.
The error:
ERROR: syntax error at or near "\"
LINE 1: ...a (meta_id, comment_id, meta_key, meta_value) FROM stdin; \.
^
********** Error **********
ERROR: syntax error at or near "\"
SQL state: 42601
Character: 77
points to the \ in the \. as being the issue.
Are you sure you require the \.?
Per the documentation:
End of data can be represented by a single line containing just
backslash-period (.). An end-of-data marker is not necessary when
reading from a file, since the end of file serves perfectly well; it
is needed only when copying data to or from client applications using
pre-3.0 client protocol.
Try removing your \. from the line and see if your copy works as expected.