Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id C704E476373 for ; Thu, 30 Jan 2003 10:15:06 -0500 (EST) Received: from ns.aprote.ee (ns.aprote.ee [80.235.78.106]) by postgresql.org (Postfix) with ESMTP id 5C5A447751A for ; Thu, 30 Jan 2003 10:15:02 -0500 (EST) Received: Message by Barricade ns.aprote.ee with ESMTP id h0UFFc311203 for ; Thu, 30 Jan 2003 17:15:38 +0200 Received: from TAMBETM ([192.168.1.14]) by black.aprote.com with Microsoft SMTPSVC(5.0.2195.5329); Thu, 30 Jan 2003 17:15:04 +0200 Message-ID: <000c01c2c872$5d18ab80$0e01a8c0@aprote.com> From: "Tambet Matiisen" To: "Thiago Conti" , "pgsql-sql" References: <00d001c2c86f$8414dcc0$0c00000a@camburi> Subject: Re: Function executing twice Date: Thu, 30 Jan 2003 17:15:03 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-OriginalArrivalTime: 30 Jan 2003 15:15:04.0055 (UTC) FILETIME=[5D83F070:01C2C872] X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/503 X-Sequence-Number: 11368 I think you should first check your application logic, for example print something out just before calling the function. Then you can easily see, if the problem is in PostgreSQL or in your application. I once had similar problem, when I used function as argument to COALESCE. COALESCE is translated to CASE before evaluating the arguments. For example COALESCE(id,nextval('id_seq')) becomes CASE WHEN id IS NOT NULL THEN id WHEN nextval('id_seq') IS NOT NULL THEN nextval('id_seq') ELSE NULL END. As you can see, when id is null, the sequence id_seq is incremented twice. Solution was quite simple, I just used CASE directly: CASE WHEN id IS NOT NULL THEN id ELSE nextval('id_seq') END. Tambet ----- Original Message ----- From: Thiago Conti To: pgsql-sql Sent: Thursday, January 30, 2003 4:54 PM Subject: [SQL] Function executing twice Hello, I'm executing a function with this command: select function_name(aaa,bbb,ccc); When I do it on PSQL or PGAdmin it works perfectly. However, on my application the function is executed twice. Has anybody faced a problem like this? I'm using PostgreSQL 7.2.3 and ODBC conection. Thanks