Subject Re: INSERT / CREATE if non-existent
Author lutterot
--- In firebird-support@yahoogroups.com, "lutterot" <lutteroth@...> wrote:
>
> Hi!
>
> I am looking for a good way to create a table if a table of the same
> name does not exist, and inserting a row if a row with the same
> primary key value does not exist, for many rows and tables. That is, I
> need to merge data and metadata into an existing DB using an SQL
> script. I have heard that the upcoming Firebird version will support
> an INSERT OR UPDATE, but I don't know any details.
>
> I have tried something like this:
>
> EXECUTE BLOCK AS BEGIN
> INSERT ...
> CREATE TABLE ...
>
> WHEN SQLCODE <0 DO CONTINUE;
> END;
>
> ...but for some syntactic reason it could not be executed.

I have read now that DDL cannot be executed in a stored procedure, so
the CREATE TABLE in EXECUTE BLOCK seems to be forbidden as well.
However, I am still wondering if there isn't a simple way to make
Firebird ignore errors in an SQL script, so that the transaction
continues.

There was some discussion on the developer mailing list about an
CREATE OR ALTER TABLE or UPGRADE statement that would solve the
problem, but it does not seem to be implemented.

Cheers,
Christof