Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gi7na-0002AK-PP for pgsql-general@arkaria.postgresql.org; Sat, 12 Jan 2019 01:09:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gi7nX-0005Cb-T9 for pgsql-general@arkaria.postgresql.org; Sat, 12 Jan 2019 01:09:15 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1gi7nW-00056M-Js for pgsql-general@lists.postgresql.org; Sat, 12 Jan 2019 01:09:15 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gi7nO-0006Tg-MS for pgsql-general@lists.postgresql.org; Sat, 12 Jan 2019 01:09:14 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 6CE8A23AE6; Fri, 11 Jan 2019 20:09:03 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 11 Jan 2019 20:09:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=z llvASxal6uvFs+d1utR5UuWkYcd8DK5q3rOiVj18x8=; b=1IILaulf0MFOlu8de UOuqd+U+SxufoLJl5W0//VbtwDYaqWW9YgkmVymAp9bgjvhb5ZqS9Uq5fnYnBnM0 Ocl1dgJdX+nHbReq9nIcVs0w4D6VfWbY5UBNRBCt3xkYLUAWzoOH4/yWV3N9FAvZ 1DLWjaC+mpWejxBhNGyVFA1/M5sthhWhzf/ej0wbLf4FLI4Xhcwy4F6MFkKvDZX6 KIHwL+K4d0CCkuktlwLB8aYk+Ewm8oCStHADCMTCO2BWn09lVXxI2WQEYhwKz7JJ /6rXDOQWrfiv1O/3GrenTkueXYhFiEe5PJNXtOeuHyax1dmhnh2o0/ql2yanTCYZ 8ErDw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=zllvASxal6uvFs+d1utR5UuWkYcd8DK5q3rOiVj18 x8=; b=ZJEwhMcnXTRFFoK/XY6Mqz012AaIO2BP15DOjR2kHop29rNabYvCvXPDC yGVWF5cL/bh4HBydnQWlfkiiRpmdL+Ptg5up6/IL55LAmZkWmAAcuI43/gWlpkh0 Y/HgafjfFhp31NpsjFWXZqAu/WZT2EXgCDpIDYt0nT7P3d9teeowk/EtcCwTCPiM SJlp9r/R+3YUvU1uTxz1vGkBUD3yYTPF5LPGBTwhNiZvT2whABOE2PdBedAAfVi7 qwZblrrWHFBOcnpnH4KSswR5iBZrc4glesE6C4qmrltWtkYWipVyJwmP1EdH1c+8 fXlZRZW8dYHY0zY6KHccMUSQLM92w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtledrfeeigddvkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfhuthenuceurghilhhouhhtmecufedt tdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhepuffvfhfhkffffg ggjggtgfesthekredttdefjeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegr ughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmqeenucfkphepjedurddvud dvrddufeegrdefnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghv vghrsegrkhhlrghvvghrrdgtohhmnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from [192.168.1.2] (unknown [71.212.134.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 9347AE41AC; Fri, 11 Jan 2019 20:09:01 -0500 (EST) Subject: Re: insert into: NULL in date column To: Rich Shepard , pgsql-general@lists.postgresql.org References: <410b055a-24a7-5e15-f4e6-462e64794530@gmail.com> From: Adrian Klaver Message-ID: Date: Fri, 11 Jan 2019 17:09:00 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 1/11/19 4:00 PM, Rich Shepard wrote: > On Fri, 11 Jan 2019, Ken Tanzer wrote: > >> I think the problem is actually that you're trying to represent your NULL >> dates with '', which PG doesn't like. > > Ken, > >   That's certainly how I saw the error message. > >> cat test.csv >> >> my_text,my_date,my_int >> 'Some Text','1/1/18',3 >> 'More Text,,2 >> 'Enough','',1 >> >> CREATE TEMP TABLE my_test (my_text TEXT, my_date DATE, my_int INT); >> >> \copy my_test FROM test.csv WITH CSV HEADER >> >> ERROR:  invalid input syntax for type date: "''" >> CONTEXT:  COPY my_test, line 4, column my_date: "''" >> >> >> You'll note that it breaks on the last line, which is like yours, not >> the one before it. > >   Huh! I'll leave off the quote marks and see if that makes a > difference ... > tomorrow morning. Since dates are treated as strings I thought their > absence > also needed the quotes. Stay tuned to this mail list for test results. Dates are not treated as strings they are treated as dates. There is built casting for strings that are valid dates though: create table date_test(dt_fld date); insert into date_test values('01/11/19'); INSERT 0 1 --Trying MySQL 'null':) insert into date_test values('00/00/0000'); ERROR: date/time field value out of range: "00/00/0000" LINE 1: insert into date_test values('00/00/0000'); insert into date_test values(''); ERROR: invalid input syntax for type date: "" LINE 1: insert into date_test values(''); As pointed out you are being told '' is not a valid date. > > Thanks, > > Rich > > -- Adrian Klaver adrian.klaver@aklaver.com