Reputation: 869
I'm trying to insert couple of million rows into a PostgreSQL database. I am wondering what is the best way to do it.
I'm looking to see which one is better and why? I have read through some blogs but still couldn't come to a conclusion.
I think INSERT INTO is a bulk insert operation. Please correct me if I'm wrong. Whether CREATE TABLE AS SELECT is a bulk insert operation?
Please advise.
Upvotes: 0
Views: 2081
Reputation: 33704
CREATE TABLE AS
is a bulk insert operation as well. The main difference is that CREATE TABLE AS
is easier to optimize for PostgreSQL; it is clear that no WAL information has to be written (unless WAL-based replication is active, of course). See the wal_level
documentation and Disable WAL Archival and Streaming Replication for some other cases where this optimization applies.
Upvotes: 4