You can simply use:

PRAGMA table_info('my_table')

To get a list of columns, which you can check against and then
conditionally add your column.

On Wed, Aug 1, 2018 at 9:13 AM, Tim Streater <t...@clothears.org.uk> wrote:

> On 01 Aug 2018, at 14:34, Simon White <simonwh...@dciphercomputing.com>
> wrote:
>
> > I would like to suggest the addition of the "If not exists" to the Add
> > Column feature of SQLite.  There are quite common situations where
> > ensuring a column exists is important so that an update to remote
> > devices will not fail but it is not so important that deprecated fields
> > be removed.  This is often the case with backward compatibility.  New
> > columns will not affect old systems but allows all remote devices
> > running older software to be updated using the same process as new
> > devices.  Once the hardware reaches end of life it will be replaced and
> > the new hardware will use the new columns.  So having the ability to
> > Alter the table with a series of Add Column commands ensures that the
> > new records included in the update are added to the table.  These is
> > especially true for limited remote devices where full database
> > management is not feasible.  In this scenario all that is required is
> > that the required columns exist.  So to be able to alter the table with
> > a standard SQL command is the most efficient method on such devices.
> > Developing scripts to drop and re-create and re-load tables on hundreds
> > of remote devices greatly increases the risk of failures. Having the "if
> > not exists" would remove all of this potential complexity and allow a
> > quick and easy method to ensure the column exists in the table.
>
> I'd like to second this and for just the same reasons. Something like:
>
>    alter table add column if not exists my_new_col ...;
>
> I would find very helpful.
>
>
> --
> Cheers  --  Tim
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to