user3467349
user3467349

Reputation: 3191

sqlite insert with default values for default fields

The docs specify two alternatives: insert values or insert default values (https://www.sqlite.org/lang_insert.html)

The trouble is if one for example has a table:

create table address_book values(
 rowid integer primary key, 
 first_name, 
 last_name, 
 address, 
 phone_number, 
 email, notes, 
 country TEXT DEFAULT 'USA'
 )

One can no longer write insert into values(?, ?, ?, ?, ?, ?) since it expects rowid and country to be specified. Is there a shortcut for specifying insert into values with default values populating the default fields? Or is impossible without explicitly naming all the non-default fields?

Upvotes: 0

Views: 954

Answers (1)

Larry Lustig
Larry Lustig

Reputation: 50970

Yes, it is impossible. In any event it is good practice to explicitly name the columns you are INSERTing into anyway -- leaving the columns out leads to more fragile code and more "silent failure" possibilities in which you're not inserting data into the column you think you are inserting it into.

Upvotes: 1

Related Questions