Thread: COPY doesn't like my dates on STDIN

COPY doesn't like my dates on STDIN

From
James Long
Date:
I'm trying to

copy temp_table ( id, date_created ) from stdin;
TME     2008-03-18
\.

pgsql says:

ERROR:  column "date_created" is of type date but expression is of type character
HINT:  You will need to rewrite or cast the expression.

I basically grok what it is saying, but the "expression" is in the
STDIN stream.  How do I cast that?  And I also don't get why my
pg_dump backup scripts use this same syntax but I can't.

One such pg_dump-created file says:

COPY tickets (ticket_number, reservation_number, travel_date, issue_date, ... )
FROM stdin;
2115492091826   11ACFD  2006-08-28      \N      ...

Certainly, no criticism intended.  I really enjoy PG.  Just
confusion on my part is all.

Thank you,

Jim

Re: COPY doesn't like my dates on STDIN

From
James Long
Date:
My bad, I apologize.  The error was not being thrown by the
COPY statement, but by a later INSERT.

The syslog showed me this:

Mar 18 22:32:02 ns postgres[70347]: [6-1] ERROR:  syntax error at or near "2008" at character 1
Mar 18 22:32:02 ns postgres[70347]: [6-2] STATEMENT:  2008-03-18
Mar 18 22:32:02 ns postgres[70347]: [6-3]       insert into table_name
Mar 18 22:32:02 ns postgres[70347]: [6-4]       select * from temp_table;

I thought that INSERT would match up like-named fields, but
it appears to match fields up in the order they appear in
the schema.  If suppose to match up like names, one
must specify the ( field, names ) in the INSERT and SELECT
statements.

Jim


On Tue, Mar 18, 2008 at 08:31:41PM -0700, James Long wrote:
> I'm trying to
>
> copy temp_table ( id, date_created ) from stdin;
> TME     2008-03-18
> \.
>
> pgsql says:
>
> ERROR:  column "date_created" is of type date but expression is of type character
> HINT:  You will need to rewrite or cast the expression.
>
> I basically grok what it is saying, but the "expression" is in the
> STDIN stream.  How do I cast that?  And I also don't get why my
> pg_dump backup scripts use this same syntax but I can't.
>
> One such pg_dump-created file says:
>
> COPY tickets (ticket_number, reservation_number, travel_date, issue_date, ... )
> FROM stdin;
> 2115492091826   11ACFD  2006-08-28      \N      ...
>
> Certainly, no criticism intended.  I really enjoy PG.  Just
> confusion on my part is all.
>
> Thank you,
>
> Jim
>
> --
> Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-novice