Why can't I create this SQLite view using the command line?

137 views Asked by At

When I run the query below in SQLiteStudio, the view is successfully created.

CREATE VIEW BeatsEventsView AS
    SELECT BeatId,
           EventId,
           Hero,
           Beat,
           AdaptationPhase,
           Essence,
           Act,
           Events.[Desc]
      FROM BeatEvents,
           Beats,
           Events
     WHERE (BeatEvents.EventId = Events.Id) AND 
           (BeatEvents.BeatId = Beats.Id);

However, I get Error: near line 1: near "CREATE": syntax error if I put it into a file and run the command below.

sqlite3 $DB_FILE < $BASE_DIR/src/BeatsEventsView.sql.txt   

How can I create this view in a shell script?

Running the command file BeatsEventsView.sql.txt results in this output:

BeatsEventsView.sql.txt: UTF-8 Unicode (with BOM) text
1

There are 1 answers

0
Glory to Russia On BEST ANSWER

Thanks to the help of @Shawn I fixed the error by adding

-- -*- mode: sql; coding: utf-8 -*-

at the beginning of the file so that it looks like shown below.

-- -*- mode: sql; coding: utf-8 -*-
CREATE VIEW BeatsEventsView AS
    SELECT BeatId,
           EventId,
...

After saving it with Emacs, the file BeatsEventsView.sql.txt command now returns

BeatsEventsView.sql.txt: ASCII text