Sarfaraz Makandar
Sarfaraz Makandar

Reputation: 6733

Copy *.csv file to view in PostgreSQL

I want to import data from *.csv file to view in the PostgreSQL with 9.3 version. Here is the following script I have tried.

Example:

\copy "viewName" from 'D:\filename.csv' DELIMITER ';' CSV HEADER;

Error

ERROR:  cannot copy to view "viewName"    

Questions:

Upvotes: 2

Views: 2632

Answers (1)

Karl Bartel
Karl Bartel

Reputation: 3434

From http://www.postgresql.org/docs/9.3/static/sql-copy.html:

COPY can only be used with plain tables, not with views. However, you can write COPY (SELECT * FROM viewname) TO ....

Since COPY is the basis for \copy, you might want to try your code with a table instead of a view and the select from there.

Upvotes: 2

Related Questions