Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aT0CK-0000Uu-1q for pgsql-bugs@arkaria.postgresql.org; Tue, 09 Feb 2016 04:46:44 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aT0CJ-0003yZ-G7 for pgsql-bugs@arkaria.postgresql.org; Tue, 09 Feb 2016 04:46:43 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aT0CI-0003xx-JR for pgsql-bugs@postgresql.org; Tue, 09 Feb 2016 04:46:42 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aT0CG-0006cb-5o for pgsql-bugs@postgresql.org; Tue, 09 Feb 2016 04:46:41 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u194kcVN020634; Mon, 8 Feb 2016 23:46:38 -0500 From: Tom Lane To: mail@eaden.net cc: pgsql-bugs@postgresql.org Subject: Re: BUG #13919: Cast error when table is empty. In-reply-to: <20160205113528.2660.62254@wrigleys.postgresql.org> References: <20160205113528.2660.62254@wrigleys.postgresql.org> Comments: In-reply-to mail@eaden.net message dated "Fri, 05 Feb 2016 11:35:28 +0000" Date: Mon, 08 Feb 2016 23:46:38 -0500 Message-ID: <20633.1454993198@sss.pgh.pa.us> X-Pg-Spam-Score: -2.2 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org mail@eaden.net writes: > When trying to change the type of column I received the error : > PG::DatatypeMismatch: ERROR: column "date_of_birth" cannot be cast > automatically to type date > HINT: Specify a USING expression to perform the conversion. > I totally understand the error. However, there are no rows in the table, so > it IS possible to automatically to cast 0 strings into 0 dates. > If there are no rows, can the column type just be changed? I do not see a good reason to create a special case for this. If there's no data in the table, and you don't feel like creating a fully valid ALTER command, why don't you just drop and recreate the table? Or for that matter you could just make up some useless USING expression, say USING NULL::date. (Also, I believe we apply the USING expression to the column's default value, and also to indexes if any, so "there are no rows" is far from a complete statement of the restrictions that would have to apply before ignoring the lack of a datatype transform could work.) regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs