On 28 Jun 2018, at 9:21am, Константин Краснов <[email protected]> wrote:

> However, a table with name " my-test-table" was created in the database and
> is empty
> 
> sqlite> .schema
> CREATE TABLE [my-test-table](
>  "col1" TEXT,
>  "col2" TEXT
> );

Dear Konstantin,

The above is not showing a table with the name "my-test-table".  The brackets 
you see are part of the table name.  So the table is called "[my-test-table]".  
This is the cause of your problem:

SQLite version 3.22.0 2017-12-05 15:00:17
[...]
sqlite> .import 'my-test-table.csv' [my-test-table]
Error: no such table: [my-test-table]
sqlite> .schema
CREATE TABLE [my-test-table](
  "col1" TEXT,
  "col2" TEXT
);
sqlite> .import 'my-test-table.csv' testTable
sqlite> .schema
CREATE TABLE [my-test-table](
  "col1" TEXT,
  "col2" TEXT
);
CREATE TABLE testTable(
  "col1" TEXT,
  "col2" TEXT
);
sqlite> .import 'my-test-table.csv' test-table
Error: near "-": syntax error
sqlite> .import 'my-test-table.csv' [testTable]
Error: no such table: [testTable]

The problem seems to be that either the shell tool or SQLite itself is not 
consistent in how it understands square brackets around table names.

Using square brackets around identifiers is not standard SQL.  It's used by SQL 
Server and SQLite allows it in some places for compatibility with SQL Server.  
And of course, as the above shows, without the square brackets around the 
identifier you can't use the '-' character as part of an identifier name.

Whether these is considered bugs or not, and whether they will be fixed or not, 
are things I don't know.  Perhaps one of the developer team will comment.

If you are writing code from scratch I recommend that you use identifiers like 
"MyTestTable" instead of "[my-test-table]".  On the other hand if you are 
trying to transfer hundreds of lines of existing SQL Server code then you might 
want to wait for a response from the SQLite developer team.

Hope this helps.

Simon.
_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to