Subject | Re: How can I skip an Insert ? |
---|---|
Author | yazbeckmona |
Post date | 2005-08-11T18:44:57Z |
--- In firebird-support@yahoogroups.com, Steve Wiser <steve@s...>
wrote:
wrote:
> On Thu, 2005-08-11 at 15:17 +0000, yazbeckmona wrote:wrote:
>
> > --- In firebird-support@yahoogroups.com, "Adam" <s3057043@y...>
> > > --- In firebird-support@yahoogroups.com, "yazbeckmona"that
> > > <yazbeckmona@y...> wrote:
> > > > Hello,
> > > >
> > > > I would like to add something to my trigger "BeforeInsert"
> > > wouldI do
> > > > ignore every line that is already in the database. How could
> > > > that, I have absolutely no idea, I never worked with triggereverything
> > > before! I
> > > > need to NOT insert lines that is already in the database (of
> > > course,
> > > > because now I have some primary key duplicate error). (And I
> > don't
> > > > want to change my SQL query, because I tried already
> > andunique.
> > > it
> > > > is terribly long.)
> > > >
> > > > Here's my trigger with a key generator:
> > > > AS
> > > > BEGIN
> > > > if (NEW.idemployeur IS null) then
> > > > NEW.idEmployeur = GEN_ID(G_EmployeuridEmployeurGen7, 1);
> > > > END
> > > >
> > > > Thank you so much for any help!
> > >
> > > Triggers do not appear to be what you want.
> > >
> > > You seem a little confused about the role of the queries etc.
> > > Firebird will raise an exception if your primary key is not
> > > In other words, you must be supplying a idEmployeur that isalready
> > > in the table (a duplicate), and that is against the wholeconcept
> > ofdatabase
> > > a primary key. Your application should catch the exception and
> > react
> > > accordingly. It would be very confusing logic to have the
> > > quietly eat any duplicate data, you would not then know whereyour
> > > record went. Instead, you now have a mechanism where thedatabase
> > > informs you that the query operation failed, and why it failed.Use
> > > it to your advantage.insert
> > >
> > > In fact, the way you would do input validation in the before
> > > trigger would be to raise a custom exception to prevent theinsert
> > > from succeeding.tab2).
> > >
> > > Adam
> >
> > Hello,
> >
> > The thing I am trying to do is that I have 2 tables (tab1 and
> > I want to store the data form tab1 in tab2 IF tab2 doesn'talready
> > have it. It is so simple, I do this usually but now, the tableare
> > too large and when I write my query using something likeid
> > INSERT id, c1, c2, c3 IN tab2 FROM tab1 WHERE NOT EXISTS (SELECT
> > FROM tab2 WHERE tab1.id = tab2.id) it is really terribly long.Yes it is, and they are indexes!
>
>
> This query is slow even when you are searching by the primary key?
>
>write
> >
> > So that's why I wanted to skip the insert instead. So How can I
> > a try and catch exception in the trigger? Hopping it will be alittle
> > faster than the query...
> >
> > thanks
> >
> >
> >
> >
> >
> >
> >
> > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >
> > Visit http://firebird.sourceforge.net and click the Resources item
> > on the main (top) menu. Try Knowledgebase and FAQ links !
> >
> > Also search the knowledgebases at http://www.ibphoenix.com
> >
> > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
>
>
> [Non-text portions of this message have been removed]