Re: plpgsql function to insert or update problem

From: Andy Colson <andy(at)squeakycode(dot)net>
To: Alban Hertroys <haramrae(at)gmail(dot)com>
Cc: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: plpgsql function to insert or update problem
Date: 2012-03-24 14:28:25
Message-ID: 4F6DDA09.70903@squeakycode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 03/24/2012 05:23 AM, Alban Hertroys wrote:
> On 23 Mar 2012, at 19:49, Andy Colson wrote:
>
>> Anyway, the problem. I get a lot of DB Error messages:
>> DB Error: ERROR: duplicate key value violates unique constraint "by_ip_pk"
>> DETAIL: Key (ip, sessid, "time")=(97.64.237.59, 2qggi9gcdkcaoecqg3arvo1gu7, 2012-03-23 13:00:00) already exists.
>> CONTEXT: SQL statement "insert into by_ip(vhost, time, ip, sessid, hits)
>> values (vid, date_trunc('hour', ihittime), iip, isessid, 1)"
>
>> Why is it hitting the insert statement? Why doesn't the "if not found" seem to work? Any hints would be appreciated.
>
>
> You forgot about vid in your PK ;)
>
> Alban Hertroys
>
> --
> If you can't see the forest for the trees,
> cut the trees and you'll find there is no forest.
>
>

Wow, jeez... I don't know how many times I looked at that. Thank you very much!

> If you can't see the forest for the trees,

Your sig is appropriate :-)

-Andy

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andreas 2012-03-24 22:52:04 Howto Replication for dummies?
Previous Message Bruce Momjian 2012-03-24 11:44:35 Re: pgcon 2012