Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fm0YM-0003M4-7k for pgsql-general@arkaria.postgresql.org; Sat, 04 Aug 2018 17:41:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fm0YK-0004u5-Cg for pgsql-general@arkaria.postgresql.org; Sat, 04 Aug 2018 17:41:20 +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.89) (envelope-from ) id 1fm0YI-0004tr-Eb for pgsql-general@lists.postgresql.org; Sat, 04 Aug 2018 17:41:20 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fm0YE-00035H-1c for pgsql-general@lists.postgresql.org; Sat, 04 Aug 2018 17:41:17 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id DA06621F2F; Sat, 4 Aug 2018 13:41:12 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Sat, 04 Aug 2018 13:41:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= 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; s=fm3; bh=W7fHp22OiprH1OtEERY4nvW+qBpgk GXESFC8qfXOKaI=; b=G8paQIh6Fz25PWnqP2QFy1K8EgkFPjqqUvxlNHukqES9Y SDtuOsBu9eyRK+8AQdU31CesmZe0wbU26mxm09pgsf4HbQQylO8al7wHaM/swwTz Ng00Z5Ts3QCwFKWQbdig1Ukm30i/hA2svIoEO2ImwOa2UeQbg51hrjX4/NhBjxDT mLR0EKamyXi67qP6wUiUpaTWEaVGzmBrXQ/0Tw233fvePLV+ECVm/A3OGH/rgmtc xFiGFx4Nb1MX6eoRo62eB3ttxEf4KuHv0n+AdrZMmmCMDLNC9uNCOTRNvroiFDpK /W6dVh2UGpPI88qBbJxwlz6LyKQfIrDdE+vrITuOw== 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-sender:x-me-sender:x-sasl-enc; s=fm3; bh=W7fHp2 2OiprH1OtEERY4nvW+qBpgkGXESFC8qfXOKaI=; b=Y0NatRe8OtSlwTWfbB8r4X rPyHCzuGysTzRS9xKI61g8DL4+GSz4iuVWlas6g/DVOsQRopbJ4CknMrNp1tc18j 6ecLir4kwbQGQyvIhBAmg3H+ECezICTE7fRsByvXYghGGUiK/FF8MfeTcYD3nNn0 Z8KVKjM8XLbaCUmiXrvy9Wsyupddb5CxeL1/+Y1iIrYdmbkxAbWhj/evKDZx8EQx 8cwh4XhKb/QFZQ+m3lyVhA/OMxD3YidHRTT7Mo7OQAUvZKx1rkLViKxxdx79mTlO 4m6hH8Arvobl2IW/LV3Ut0VT7EYdYeeqFfBz7g5/41iowWpBNJLgpDWLIvpLxSlg == X-ME-Proxy: X-ME-Sender: Received: from [192.168.1.3] (unknown [71.212.134.181]) by mail.messagingengine.com (Postfix) with ESMTPA id 317F0E4040; Sat, 4 Aug 2018 13:41:12 -0400 (EDT) Subject: Re: Add column with If Not Exists To: Simon White , pgsql-general@lists.postgresql.org References: <9bf027c0-ed29-852c-b5c0-49b166b792cf@dciphercomputing.com> From: Adrian Klaver Message-ID: Date: Sat, 4 Aug 2018 10:41:11 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <9bf027c0-ed29-852c-b5c0-49b166b792cf@dciphercomputing.com> 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 08/04/2018 08:56 AM, Simon White wrote: > Hi > > I would like to suggest the addition of the "If not exists" to the Add > Column feature of Postgres.  There are quite common situations where > ensuring a column exists is important so that an update to remote > devices will not fail but it is not so important that deprecated fields > be removed.  This is often the case with backward compatibility.  New > columns will not affect old systems but allows all remote devices > running older software to be updated using the same process as new > devices.  Once the hardware reaches end of life it will be replaced and > the new hardware will use the new columns.  So having the ability to > Alter the table with a series of Add Column commands ensures that the > new records included in the update are added to the table.  Having the > "if not exists" would remove all of this potential complexity and allows > a quick and easy method to ensure the column exists in the table using > simple SQL commands that will not cause errors if the column is already > present. Sort of like this: https://www.postgresql.org/docs/9.6/static/sql-altertable.html "ADD [ COLUMN ] [ IF NOT EXISTS ] ..." in 9.6+ > > I understand that some people will feel this is not the recommended way > to proceed.  I understand there are lots of ways this can be handled > differently as I have been working with database of various kinds for > over 30 years.  All I am suggesting is that this feature would be nice > to have in some scenarios and thus would like it considered.  I do not > wish to start a discussion on whether using it is a sound approach or > not as that is a different discussion. > -- Adrian Klaver adrian.klaver@aklaver.com