X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 872065280B for ; Mon, 13 Jun 2005 11:22:37 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 31972-07 for ; Mon, 13 Jun 2005 14:22:33 +0000 (GMT) Received: from srv1.xmlrevenue.com (unknown [204.9.187.132]) by svr1.postgresql.org (Postfix) with ESMTP id 7461F52926 for ; Mon, 13 Jun 2005 11:22:31 -0300 (ADT) Received: from [212.112.107.15] (helo=MainComputer) by srv1.xmlrevenue.com with esmtp (Exim 4.44) id 1Dhppf-0000Yz-Ob for pgsql-general@postgresql.org; Mon, 13 Jun 2005 10:22:32 -0400 Date: Mon, 13 Jun 2005 20:22:39 +0400 From: "ON.KG" X-Mailer: The Bat! (v2.01) Reply-To: "ON.KG" Organization: UnCLouds X-Priority: 3 (Normal) Message-ID: <10813889593.20050613202239@on.kg> To: pgsql-general@postgresql.org Subject: duplicate key violates unique constraint In-Reply-To: <20050610095655.0215752956@svr1.postgresql.org> References: <42A95936.3060002@archonet.com> <20050610095655.0215752956@svr1.postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - srv1.xmlrevenue.com X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - on.kg X-Source: X-Source-Args: X-Source-Dir: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.174 tagged_above=0 required=5 tests=AWL, UPPERCASE_25_50 X-Spam-Level: X-Archive-Number: 200506/620 X-Sequence-Number: 79328 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