Subject | RE: [firebird-support] Is it possible to perform such insert? |
---|---|
Author | Svein Erling Tysvær |
Post date | 2012-11-19T07:49:37Z |
>>Can not I do something like this:Sorry
>>INSERT INTO MYTABLE SELECT EXPLICT_VAL1, EXPLICT_VAL2, T.*(ALL BUT
>>FIRST TWO COLUMNS) FROM MYTABLE T WHERE T.RECORD_ID = 50;
>
>No, it is not quite that simple. However, if you're on a recent Firebird version, you can do something like this:
>
>execute block as
> declare variable s varchar(2000);
> declare variable s2 varchar(2000);
>begin
> select list(trim(rdb$field_name))
> from rdb$relation_fields
> where rdb$relation_name = 'MYTABLE'
> and rdb$field_name not in ('ID', 'DUMMY') into :s;
> select 'INSERT INTO MYTABLE( FIRST_COLUMN, SECOND_COLUMN,' || :s || ') SELECT GEN_ID(MY_GENERATOR, 1), EXPLICIT_VAL, ' || :s || ' FROM MYTABLE WHERE RECORD_ID = 50'
> from rdb$database
> into :s2;
> execute statement s2;
>end
> and rdb$field_name not in ('ID', 'DUMMY') into :s;should of course be:
and rdb$field_name not in ('FIRST_COLUMN', 'SECOND_COLUMN') into :s;
Set