开发者

Copying an entire table with Postgres

开发者 https://www.devze.com 2022-12-29 00:37 出处:网络
I\'m trying to copy the contents of one table into another in Postgres, however it appears some rows aren\'t being copied correctly:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消