add column to table if not exists
[email protected] Sat, 4 May 2019 07:50:26 +0200
| Newsgroups | gmane.comp.java.hsqldb.user |
|---|---|
| Message-ID | <CAE7SmwptV_kqbvttQ98mHA_wZT2YokcPQUkaxxXn5sqoBmFXgA@mail.gmail.com> |
Trying to add column column1 to table1 if it doesn't exist yet:
create table if not exists table1( column2 varchar(20));
CREATE PROCEDURE column_present()
MODIFIES SQL DATA
BEGIN ATOMIC
DECLARE column_count integer;
set column_count = select COUNT(*) from
information_schema.system_columns Where table_name = 'table1' and
column_name = 'column1';
if column_count = 0 then alter table table1 ADD column1 integer;
end if;
END;
call column_present();
results in:
[2019-05-03 22:28:13] [42581][-5581] unexpected token: ALTER : line: 6
[2019-05-03 22:28:13] java.lang.RuntimeException: org.hsqldb.HsqlException:
unexpected token: ALTER : line: 6
[2019-05-03 22:28:13] at org.hsqldb.error.Error.parseError(Unknown Source)
what is the proper way to create the column in existing table (if it
doesn't exist yet) in the HSQLDB?
Please note: ignoring the error on creation if it already exists, is not an
option for me.
_______________________________________________
Hsqldb-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/hsqldb-user