Re: Implement a logging table; avoiding conflicting inserts
> Given: MySQL 4.0.12, I need to implement a pageview log with a
> resolution of 1 day.
>
> I propose this table:
>
> CREATE TABLE `pageviews` (
> `id` int(11) NOT NULL auto_increment,
> `date` date NOT NULL default '0000-00-00',
> `url` char(120) NOT NULL default '',
> `views` mediumint(9) NOT NULL default '0',
> PRIMARY KEY (`id`),
> UNIQUE KEY `date` (`date`,`url`),
> KEY `url` (`url`)
>) TYPE=InnoDB;>>>>>>
>
>
> So that an update will look like:
> > UPDATE pageviews SET views=views+1 WHERE date='<DATE>' AND
> url='<ARTIST>'
>
> Of course I need to INSERT the record if one does not match my WHERE.
> This would be easy if I had 4.1 -- "INSERT ... ON DUPLICATE KEY UPDATE",
> I think -- but I do not.
Would the "REPLACE" method work?
David
|