1

I have a table with a column of type "timestamp with timezone"

I'm importing data from a file with this command

db=# COPY "temperature"  FROM 'd:\data\PostgresImport\TEMPLOG.CSV' DELIMITER ',' CSV;

I get this error

ERROR:  malformed array literal: "2009-01-05 18:40:00 z"
DETAIL:  Array value must start with "{" or dimension information.
CONTEXT:  COPY temperature, line 1, column timestamp: "2009-01-05 18:40:00 z"

I tried re-formatting the source data to show the timezone as +0000, but I still get the same error:

ERROR:  malformed array literal: "2009-01-05 18:40:00+0000"
DETAIL:  Array value must start with "{" or dimension information.
CONTEXT:  COPY temperature, line 1, column timestamp: "2009-01-05 18:40:00+0000"

1 Answer 1

1

The column name cannot be "timestamp" - apparently that is a reserved word. Rather than flagging it as reserved when the table is created, it causes strange errors like this when importing data.

By changing the column name to "datetimestamp", the COPY FROM command works perfectly. (using the timestamp in the "2009-01-05 18:40:00+0000" format)

db=# COPY "temperature"  FROM 'd:\data\PostgresImport\TEMPLOG.CSV' DELIMITER ',' CSV;
COPY 595896
db=#

Further note: when I created the table with column "timestamp", apparently the type was created as an array:

                    Table "public.temperature"
     Column      |            Type            | Collation | Nullable |
-----------------+----------------------------+-----------+----------+
timestamp        | timestamp with time zone[] |           |          | 

When I recreated the table with "datetimestamp" the column is no longer an array:

                         Table "public.temperature"
      Column      |           Type           | Collation | Nullable | 
------------------+--------------------------+-----------+----------+--
 datetimestamp    | timestamp with time zone |           |          |     
Sign up to request clarification or add additional context in comments.

1 Comment

It has nothing to do with your name change, it is the type definition. When the type definition format is x[] it means create array of x. So "timestamp timestamp with time zone" while is a very bad choice of names it is syntactically valid.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.