duplicate key violates unique constraint

Поиск
Список
Период
Сортировка
От ON.KG
Тема duplicate key violates unique constraint
Дата
Msg-id 10813889593.20050613202239@on.kg
обсуждение исходный текст
Ответ на Re: [SQL] Permission denied for language pltclu  ("Dinesh Pandey" <dpandey@secf.com>)
Ответы Re: duplicate key violates unique constraint  (Csaba Nagy <nagy@ecircle-ag.com>)
Re: duplicate key violates unique constraint  (Richard Huxton <dev@archonet.com>)
Список pgsql-general
Hi All!

I have table:

CREATE TABLE table1 (
   ip char(15) NOT NULL,
   hits integer NOT NULL default '1',
   PRIMARY KEY (ip)
);

So it's counting hits per each IP for current day and every day
trancated by cron:
TRUNCATE TABLE table1;

before inserting or updating this table there're some checkings,
logs, etc., so I'm using PL/PgSQL for that

after all checkings and logs I have:

      UPDATE table1
      SET hits = hits + 1
      WHERE ip = some_ip;

      IF NOT FOUND THEN
         INSERT INTO table1
            (ip)
         VALUES
            (some_ip);
      END IF;

when IP is not found in table it inserts new record into table
but in logs i see error
ERROR:  duplicate key violates unique constraint "table1"
CONTEXT:  PL/pgSQL function "insert_table1" line 68 at SQL statement

But record is inserted into table

what may be the problem?

i also tried before:
      SELECT INTO cnt hits
      FROM table1
      WHERE ip = some_ip;

      IF FOUND THEN
         UPDATE table1
         SET hits = hits + 1
         WHERE ip = some_ip;
      ELSE
         INSERT INTO table1
            (ip)
         VALUES
            (some_ip);
      END IF;

But same error still appears

Thank You


В списке pgsql-general по дате отправления:

Предыдущее
От: Howard Cole
Дата:
Сообщение: Re: Case sensitivity
Следующее
От: marcelo Cortez
Дата:
Сообщение: LOG: invalid message length