Home > OS >  Understanding Createview in SQLITE3
Understanding Createview in SQLITE3

Time:12-15

I am trying to understand CREATE VIEW command in SQLite, but getting strange view.

I have a CSV file,

table.csv / tab separated

ID   NAME   AGE ADDRESS     SALARY
1    Paul   32  California  20000.0
2    Allen  25  Texas       15000.0
3    Teddy  23  Norway      20000.0
4    Mark   25  Rich-Mond   65000.0
5    David  27  Texas       85000.0
6    Kim    22  South-Hall  45000.0
7    James  24  Houston     10000.0
  • run commands*

     sqlite3 sample.db
    
      .mode csv
    
      .import table.csv  COMPANY
    
      CREATE VIEW COMPANY_VIEW AS
      SELECT "ID", "NAME", "AGE"
      FROM  COMPANY;
    
      SELECT * FROM COMPANY_VIEW;
    

getting

"1 ",NAME,"32 "
"2 ",NAME,"25 "
"3 ",NAME,"23 "
"4 ",NAME,"25 "
"5 ",NAME,"27 "
"6 ",NAME,"22 "
"7 ",NAME,"24 "

Why I am not getting NAME Column. What I am doing wrong. I am an absolute beginner in SQLITE3.

CodePudding user response:

Suggest issuing .schema COMPANY and/or SELECT * FROM COMPANY before the CREATE VIEW command.

From the sqlite doc

Use the ".import" command to import CSV (comma separated value) data into an SQLite table.

The operative term here is comma separated.

Use the .separator command to change the separator to tab.

  • Related