I'm trying to copy the contents of one table into another in Postgres, however it appears some rows aren't being copied correctly:
ActiveRecord::StatementInvalid: PGError: ERROR: column "email_date" is of type timestamp without time zone but expression is of type character varying HINT: You will need to rewrite or cast the expression.
Is there any way I can have it automatically skip (or ignore) invalid rows?
Here's the query I'm using:
SET statement_timeout = 0开发者_StackOverflow中文版; INSERT INTO emails3 SELECT * FROM emails
As the message says, it's not a problem of "some invalid rows", you have incompatible types
for the email_date
column. Either fix that, or write the explicit conversion in the query.
UPDATE: If (as it seems) you want to copy the contents and the schema of the table (i.e. create a new table with the same schema and copy the contents), you can do it simply with a SELECT INTO.
精彩评论