Wednesday, August 4, 2010

Alternate to insert ignore or insert with 'where not exist' option used in Oracle/mysql

insert into
                training_counter (counter_ip,counter_date,counter_page)
select
                '10.123.13.60',
                '2010-08-04 10:42:53',
                '/drupaltraining/'
where (
                select
                            DISTINCT case
                            when count(*) = 0
                            then

                                    true
                            when (
                                select
                                            true
                                 from
                                            training_counter
                                 where
                                            (counter_ip='10.123.13.60' AND
                                             counter_date='2010-08-04 10:42:53' AND
                                             counter_page='/drupaltraining/'
                                            )
                                )
                            then
                                      false
                            else
                                      true
                            end
)




No comments:

Post a Comment