Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are SQLite 3 type names and keywords in definitions case sensitive?

i.e. Are following declarations equivalent?

CREATE TABLE example_table (
  id INTEGER PRIMARY KEY,
  name TEXT
)

and

create table example_table (
  id integer primary key,
  name text
)

I think upper case is pain to edit, but I already spotted that the .schema command in the interactive mode remembers the case. Also the documentation always uses the upper-case versions.

like image 950
dhill Avatar asked Oct 20 '22 20:10

dhill


1 Answers

I tested it with this code and it seems that the names are case-insensitive:

CREATE TABLE table_sensitive (
       id INTEGER PRIMARY KEY,
       some_int INTEGER,
       some_text TEXT
);

create table table_insensitive (
       id integer primary key,
       some_int integer,
       some_text text
);

INSERT INTO table_sensitive ( id, some_int, some_text )
       VALUES ( 'not an integer key', 'a value', 123 );

insert into table_insensitive ( id, some_int, some_text )
       values ( 'not an integer key', 'a value', 123 );

INSERT INTO table_sensitive ( id, some_int, some_text )
       VALUES ( 0, '123', 123 );

insert into table_insensitive ( id, some_int, some_text )
       values ( 1, '123', 123 );

SELECT typeof(id), typeof(some_int), typeof(some_text) FROM table_sensitive;
select typeof(id), typeof(some_int), typeof(some_text) from table_insensitive;

The result was:

Error: near line 13: datatype mismatch
Error: near line 16: datatype mismatch
integer|integer|text
integer|integer|text

(Error on inserts with non-integer primary keys and type casting works for strings containing integers for both versions.)

This means that you can pretty much write keywords and types lowercase, which is what I wanted to know.

like image 58
dhill Avatar answered Oct 29 '22 22:10

dhill