Subject Re: [firebird-support] Re: INSERT INTO ... RETURNING with EXECUTE STATEMENT
Author Tim Ward
Thanks - the procedure does actually compile if I do that, which is a good indication! (I can't actually try running it just yet.)

On 23/06/2014 13:12, Dmitry Yemanov dimitr@... [firebird-support] wrote:
 

23.06.2014 14:48, Tim Ward tdw@... [firebird-support] wrote:
>
> I've got an INSERT statement like:
>
> INSERT INTO <table>( <list of columns> )
> SELECT <list of columns>
> FROM <table whose name is not known until run time>
> WHERE <something
> RETURNING generated_primary_key INTO :variable
>
> the point being that the name of the table used in the FROM isn't known
> until run time. This needs to be inside a stored procedure for Firebird 2.1.
>
> Elsewhere (simple SELECT, FOR SELECT) I've worked out how to do this
> using EXECUTE STATEMENT.
>
> But what, please, is the correct syntax for using EXECUTE STATEMENT for
> an INSERT INTO ... SELECT ... RETURNING? - this isn't an example usage
> which I've been able to find in any of the documentation.

I believe it should be:

EXECUTE STATEMENT 'INSERT INTO ... SELECT ... RETURNING
generated_primary_key' INTO :variable;

Dmitry



-- 
Tim Ward