X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id A5E2ED1BA6E for ; Thu, 3 Jun 2004 09:14:13 -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 12681-04 for ; Thu, 3 Jun 2004 12:14:15 +0000 (GMT) Received: from anchor-post-31.mail.demon.net (anchor-post-31.mail.demon.net [194.217.242.89]) by svr1.postgresql.org (Postfix) with ESMTP id 5F9E5D1B8BB for ; Thu, 3 Jun 2004 09:14:11 -0300 (ADT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-31.mail.demon.net with esmtp (Exim 3.35 #1) id 1BVr6r-0008M4-0V; Thu, 03 Jun 2004 13:14:13 +0100 Received: from [192.168.1.17] (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 8ABEE16528; Thu, 3 Jun 2004 13:14:12 +0100 (BST) Message-ID: <40BF1614.8020404@archonet.com> Date: Thu, 03 Jun 2004 13:14:12 +0100 From: Richard Huxton User-Agent: Mozilla Thunderbird 0.6 (X11/20040502) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Mark Roberts Cc: pgsql-sql@postgresql.org Subject: Re: Date format problems References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Archive-Number: 200406/21 X-Sequence-Number: 17966 Mark Roberts wrote: > Hi im using the function below to insert data into my db; im using > now() to get the timestamptz, however when inserted in the db the format > seems to vary, the majority of the time its in the required European > style but does spontaniously change to various other type can anyone > throw any light on this problem. Not sure what you mean here. Are you saying if you insert 5 timestamps in a row, the third comes out wrong, or that all from one client are wrong, or what? > Further info: > DATESTYLE is currently set to European. > db table type is 'timestamptz' OK - first inspections seem OK. Are you sure no clients have the wrong datestyle set? > > ####################################################################################### > > CREATE FUNCTION newmess(int4, text, varchar) RETURNS varchar AS ' > DECLARE > userid ALIAS for $1; > message ALIAS for $2; > touser ALIAS for $3; > enttime DATETIME; > touserid INTEGER; > rdset BIT; > from VARCHAR; > > BEGIN > rdset = 0; > touserid=(select id from users where lastname=touser); > enttime=(select now()); Easier to say: enttime := now(); Or, just to use now() in the query below and get rid of the variable altogether. > from=(select lastname from users where id = userid); > INSERT INTO CallLog.message(message, fromuser, touser, txtime, rd, > fromusern) values(message. userid, touserid, enttime, rdset, from); > END; > ' LANGUAGE 'plpgsql'; Well, assuming this works at all (and I'm assuming you retyped it since there are some obvious syntax errors), it shouldn't be possible to insert the wrong timestamp. Whether European/American or Klingon format, now() is the current time at the server. Can you show a sample select where the timestamp is incorrect, but the ones either side are fine? I assume there is some serial message_id column that should act as a clue. -- Richard Huxton Archonet Ltd