On Fri, Sep 13, 2024 at 8:27 PM Adrian Klaver <adrian.klaver@xxxxxxxxxxx> wrote:
On 9/13/24 07:50, Adrian Klaver wrote:
> On 9/13/24 02:58, Juan Rodrigo Alejandro Burgos Mella wrote:
>> Hello, I find it unlikely that the trigger will work properly, since
>> the reserved fields of the OLD subset have no value in an INSERT
>
> I'm not seeing that the OP is asking for OLD.* values, they are just
> looking to include the result of a lookup on another table in the INSERT.
My mistake I see the OLD reference now.
>
My mistake.The trigger was supposed to use "new.col2" and fetch the corresponding lookup value from the lookup table and insert that value to the target table.
Now my question was ,in such a situation , the trigger will work fine , but is that the optimal way of doing ? Or should we convert the query someway such that the lookup table can be queried along with the INSERT at one shot from the database with a single DB call? And is it true that the trigger on the target table will suppress the batch insert and make it row by row, even if we call it in a batch fashion?
As "thiemo" mentioned , it can be done as below method, but if we have multiple lookup tables to be populated for multiple columns , then , how can the INSERT query be tweaked to cater the need here? And I understand , the lookup table can be cached in Java and refreshed at a certain point in time, but I was trying to understand if this can be doable by directly querying the database, considering the lookup tables are having large data sets in them.
Insert into tab1 (val1, val2)
Select valA, valB
From tab2
Where valC = :param1
Select valA, valB
From tab2
Where valC = :param1