Your statement is suspicious:
COPY data FROM 'data.dat' USING DELIMITERS ',' CSV;
DELIMITERS
was used in versions before 7.3. It is still supported in order not to break old code, but don't use it any more. The proper keyword is DELIMITER
. And you don't need to specify ,
at all as it is the default for FORMAT CSV
.
Also, I quote the manual here:
filename
The absolute path name of the input or output file. Windows users might need to use an E''
string and double any backslashes used in the path name.
Bold emphasis mine. Replace 'data.dat'
with something like '/path/to/data.dat'
on UNIX or E'C:\\path\\to\\data.dat'
on Windows.
For versions 7.3+ use:
COPY data FROM '/path/to/data.dat' CSV
For versions 9.0+ use:
COPY data FROM '/path/to/data.dat' (FORMAT CSV)
If you still get this error:
ERROR: invalid input syntax for type numeric:
CONTEXT: COPY data, line 13, column interval_2400:
Then, obviously, the source file does not match the structure of table data
. Have a look at your source file, go to line 13 and see what value is there for column interval_2400
. Chances are, it's not numeric. In particular, an empty string
(''
) is not allowed in columns of numeric type.
You can either fix the source file or adapt the table definition:
ALTER TABLE data ALTER COLUMN interval_2400 TYPE text;
Or whatever type is more appropriate. Might be interval
, judging from the name. (But text
accepts almost any input values.)
Or, better yet, create a modified temporary file, COPY
to it, fix offending values, then INSERT into the target table, casting from text. See: