Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c79Wy-0006lA-G6 for pgsql-odbc@arkaria.postgresql.org; Wed, 16 Nov 2016 23:22:16 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1c79Wy-0002gY-2s for pgsql-odbc@arkaria.postgresql.org; Wed, 16 Nov 2016 23:22:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1c79Wx-0002fY-Cg for pgsql-odbc@postgresql.org; Wed, 16 Nov 2016 23:22:15 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1c79Wt-0003RK-At for pgsql-odbc@postgresql.org; Wed, 16 Nov 2016 23:22:14 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 713EC20567; Wed, 16 Nov 2016 18:22:09 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute6.internal (MEProxy); Wed, 16 Nov 2016 18:22:09 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=aklaver.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=6c95nrWK0/b1ytZ 677LmO7SF+rM=; b=dsxXlF3CEb2xevjvxv1Qq6IC8x3C1TVpywcv0Q4ngswrByi KAhOd+uPD+NuacPhr2cUaldeVYO1WdaTbJpSxk35hEQZrnfVKcoBy1vNl4sF/XZz 0BJBmmXCSv7d8nW7cefnueJAYmbWxIoeoPwXqg8/9SFXvkruFh1GG0T0mvY0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s= smtpout; bh=6c95nrWK0/b1ytZ677LmO7SF+rM=; b=HuVMq9J3HoAb1L9xIaRc fvFz4kS1rhOwE0vT4I51MIxdKGrBw8drpiHQDSTsftVF37phL32GLGXq5zj4vxmk vSKG3U/+ihYq7+mTmMY2tRm262xUNqux2KPgwqrKHiYUHuxeEtS2fpL6qgsYw8J0 gU4E/OhM+bxBBvu2VALvTdA= X-ME-Sender: X-Sasl-enc: /4vjWKSZeXlIU/9PbMCqwcMDgyCRPXAiz2dLfCe7Jh3d 1479338529 Received: from [192.168.1.2] (174-21-234-69.tukw.qwest.net [174.21.234.69]) by mail.messagingengine.com (Postfix) with ESMTPA id DE9B42442C; Wed, 16 Nov 2016 18:22:08 -0500 (EST) Subject: Re: Daylight saving time rules being applied to DateTimes that don't have a timezone To: Nathan Kendall References: From: Adrian Klaver Cc: pgsql-odbc Message-ID: Date: Wed, 16 Nov 2016 15:22:08 -0800 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-odbc Precedence: bulk Sender: pgsql-odbc-owner@postgresql.org On 11/16/2016 01:09 PM, Nathan Kendall wrote: Ccing list > On 16/11/2016, Adrian Klaver wrote: >> On 11/15/2016 01:51 PM, Nathan Kendall wrote: >>> On 15/11/2016, Adrian Klaver wrote: >>>> On 11/10/2016 06:45 AM, Nathan Kendall wrote: >>>>> We are having a problem with psqlODBC versions 09.05.0100 through >>>>> 09.05.0400. With the database table schema listed below, the sample >>>>> C# test app below that fails with a violation of the primary key. >>>>> However, the same C# code works without issue when using psqlODBC >>>>> version 09.03.0400 or older. It would seem as though psqlODBC >>>>> versions from 09.05.0100 onward are applying daylight saving time >>>>> rules to DateTimes that are specified as not being associated with a >>>>> timezone. >>>> >>>> What is the error you are getting back or the value you are seeing that >>>> is different? >>> >>> With psqlODBC version 09.05.x, the DateTime value of '2016-03-13 >>> 02:00:00' is getting pushed ahead by an hour and is appearing in the >>> database as '2016-03-13 03:00:00'. This is causing the following >>> iteration of the loop ('2016-03-13 03:00:00') to fail with an >>> exception of type 'System.Data.Odbc.OdbcException': ERROR [23505] >>> ERROR: duplicate key value violates unique constraint "time_test_pk"; >>> >>> Error while executing the query >>> >>> Perhaps I should also mention that I am working on computers whose >>> operating system level timezone is set to Atlantic Standard Time, >>> which is one hour ahead of the time in New York. However, the >>> timezone should not be getting applied to a column of type "timestamp >>> without time zone". As mentioned previously, there was no problem >>> with psqlODBC 09.03.0400. >> >> Does the above mean the client you are entering the data on is in New York? > > No, I only mentioned New York as a reference point. The client and > server operating systems are both running on the Atlantic Time. The > significance of 2016-03-13 is that daylight saving time begins at 2am > on the second Sunday of March in most of North America. Yeah, 03/13/2016 2:00:00 and 03/13/2016 3:00:00 are the same time: test[5432]=# set timezone = 'America/Halifax'; SET test[5432]=# select '03/13/2016 2:00:00'::timestamptz at time zone 'utc'; timezone --------------------- 2016-03-13 06:00:00 (1 row) test[5432]=# select '03/13/2016 3:00:00'::timestamptz at time zone 'utc'; timezone --------------------- 2016-03-13 06:00:00 (1 row) So to be strictly accurate the PK constraint error is actually valid. The question remains though, what caused the change in behavior. Before I forget: What is the TimeZone set to in postgresql.conf? The answer to why the behavior changed I suspect lies in: https://odbc.postgresql.org/docs/release.html psqlODBC 09.05.0100 Release Use libpq for all communication with the server Previously, libpq was only used for authentication. Using it for all communication lets us remove a lot of duplicated code. libpq is now required for building or using libpq. Send datatype information for query parameters, when known If a query parameter is bound with a specific SQL type, pass on that information to the server. This makes the behaviour of queries like "SELECT '555' > ?" more sensible, where the result depends on whether the query parameter is interpreted as an integer or a string. I'm afraid it is going to take someone more knowledgeable of the internals to fully answer this though. > >> >>> >>> >>>> >>>>> >>>>> Nathan >>>>> >>>>> >>>>> CREATE TABLE time_test >>>>> ( >>>>> stationid character varying(8) NOT NULL, >>>>> date_time timestamp without time zone NOT NULL, >>>>> temperature double precision, >>>>> CONSTRAINT time_test_pk PRIMARY KEY (stationid, date_time) >>>>> ); >>>>> >>>>> >>>>> C# Test App Source Code: >>>>> >>>>> using System; >>>>> using System.Data.Odbc; >>>>> >>>>> namespace TimeTestApp1 >>>>> { >>>>> class Program >>>>> { >>>>> static void Main(string[] args) >>>>> { >>>>> using (var conn = new OdbcConnection("Driver={PostgreSQL >>>>> ANSI(x64)};Server=localhost;Database=weather;Uid=userGoesHere;Pwd=passGoesHere;")) >>>>> { >>>>> conn.Open(); >>>>> using (var command = new OdbcCommand("", conn)) >>>>> { >>>>> command.Parameters.Add(new OdbcParameter("stationid", >>>>> OdbcType.VarChar)); >>>>> command.Parameters.Add(new OdbcParameter("date_time", >>>>> OdbcType.DateTime)); >>>>> command.Parameters.Add(new OdbcParameter("temperature", >>>>> OdbcType.Double)); >>>>> command.CommandText = "INSERT INTO time_test (stationid, >>>>> date_time, temperature) VALUES (?, ?, ?)"; >>>>> command.CommandTimeout = 60; >>>>> command.Prepare(); >>>>> >>>>> DateTime[] testTimes = new DateTime[] { >>>>> new DateTime(2016, 3, 13, 1, 0, 0, >>>>> DateTimeKind.Unspecified), >>>>> new DateTime(2016, 3, 13, 2, 0, 0, >>>>> DateTimeKind.Unspecified), >>>>> new DateTime(2016, 3, 13, 3, 0, 0, >>>>> DateTimeKind.Unspecified) >>>>> }; >>>>> >>>>> int i = 0; >>>>> foreach (var dt in testTimes) >>>>> { >>>>> i++; >>>>> command.Parameters[0].Value = "Place"; >>>>> command.Parameters[1].Value = dt; >>>>> command.Parameters[2].Value = 60 - i; >>>>> command.ExecuteNonQuery(); >>>>> } >>>>> } >>>>> } >>>>> } >>>>> } >>>>> } >>>>> >>>>> >>>> >>>> >>>> -- >>>> Adrian Klaver >>>> adrian.klaver@aklaver.com >>>> >>> >> >> >> -- >> Adrian Klaver >> adrian.klaver@aklaver.com >> -- Adrian Klaver adrian.klaver@aklaver.com -- Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-odbc