Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

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:

  • Where I am going wrong?

  • Or I need to copy it into table then select it from there?

share|improve this question
1  
you can only COPY directly to a table, not a view – wingedpanther Aug 7 '14 at 11:38
    
@dude, Thank you dude. – Meem Aug 7 '14 at 11:43
1  
IMO COPY aTable FROM D:\filename.csv' DELIMITER ';' CSV HEADER; and then CREATE OR REPLACE VIEW viewName AS (SELECT * FROM aTable ) – wingedpanther Aug 7 '14 at 11:43
    
@dude, Yup! I got it. – Meem Aug 7 '14 at 11:44

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.