From: | yudhi s <learnerdatabase99(at)gmail(dot)com> |
---|---|
To: | Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, Juan Rodrigo Alejandro Burgos Mella <rodrigoburgosmella(at)gmail(dot)com>, Rob Sargent <robjsargent(at)gmail(dot)com> |
Cc: | pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Manual query vs trigger during data load |
Date: | 2024-09-13 19:24:49 |
Message-ID: | CAEzWdqe0VDpTi26xby+cNTMUp6goyZE1tENua08Cg-_az1mzqQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Fri, Sep 13, 2024 at 8:27 PM Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
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
From | Date | Subject | |
---|---|---|---|
Next Message | shammat | 2024-09-13 20:08:18 | Re: Will hundred of thousands of this type of query cause Parsing issue |
Previous Message | Greg Sabino Mullane | 2024-09-13 19:04:40 | Re: Will hundred of thousands of this type of query cause Parsing issue |