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 1fkHJ1-0000jG-La for pgsql-general@arkaria.postgresql.org; Mon, 30 Jul 2018 23:10:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fkHIz-0003fi-Oj for pgsql-general@arkaria.postgresql.org; Mon, 30 Jul 2018 23:10:21 +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 1fkHIy-0003dc-GH for pgsql-general@lists.postgresql.org; Mon, 30 Jul 2018 23:10:21 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fkHIq-0004O5-Tf for pgsql-general@postgresql.org; Mon, 30 Jul 2018 23:10:19 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 7E7605DA; Mon, 30 Jul 2018 19:10:11 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 30 Jul 2018 19:10:11 -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=ni9oNsnZX3rcM+gfsK5whrxwKEZWd kWk1zjPkope+2o=; b=j2yZHhz9c6MMJ8b9z4xmSvGFcuYABcOPkLyxvSuov7KGj FSmLLVqkseNaM5C6RcN8bQkb8VND6jiWVP1/sbtYpDhdaSzbjrAIX4bVYsnJCM+l yAAifISECLioma+/OaIvnunujRsRBi8P0tlVTHHy85vu2DdYWKCaGhQjpUI4oBNK v669zn5oZmxlCF+PNFPGetHH/cyRENJZ82VUWD78IuDT2mWmLU32CctnheTDPWLu awH0ltSawSAQbrgo57QX+b5uOeyyPA1CjVYmPJ0EB3Cj11WEuhG2xGYYlYIjRBEn zQirx9Ix/i4RS2buoaE+8koF8HwxfczVlS1Jk5F7g== 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=ni9oNs nZX3rcM+gfsK5whrxwKEZWdkWk1zjPkope+2o=; b=DqSV11S8aEboVkcq02yPH6 TwvVIF0/L65872cHaKSwmOoLfQ+qXxqAJeigHxVX/fXozsXYapdDOARVdI/2jKUj smeJqzlFA6O0cJ/Rx2XJdgUIbDGU8PaRAPFAk0Seh+gwd3jK7e9bjWOJEzGM+87/ UkhHZ/N1F91oMsiTcB9Ir4VsLTFk4oQcJNnAVlB+9/FaGX4uznPePJ1RHMN82dag TB08+XPxjgH0s48vW7BtfS4uFiadvLzkKCTylsy6Fmh6LW5dRCbdrQFG/fE8EmE8 /V14r1dObd81AgsObjS+LtNzLMRLPMNZ+n6iF3GjBipdXpsqdDs7vWj9oatHXzTA == 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 71AA81026B; Mon, 30 Jul 2018 19:10:10 -0400 (EDT) Subject: Re: Cosmetically-varying casts added to view definitions To: Ken Tanzer , PG-General Mailing List References: From: Adrian Klaver Message-ID: Date: Mon, 30 Jul 2018 16:10:09 -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: 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 07/30/2018 02:26 PM, Ken Tanzer wrote: > Hi.  As background/context, I'm working on a script to take a series of > databases and make them timezone-aware.  This basically involves saving > all the view definitions, dropping all the views, changing all the > timestamp columns without time zones to TS with TZ, and then recreating > all the views.  As a sanity check on all of this, I compared the > resulting view definitions to what existed before starting.  Most of > them were equivalent, with a few exceptions. > > These exceptions all seem to be where slightly different casting is used > when the view definition gets created.  For example, starting with this > view (payment_form_code is a varchar(20): > > ag_reach=> CREATE VIEW test_tmp AS (SELECT 1 FROM l_payment_form WHERE > payment_form_code IN ('CREDIT_CARD','OTHER')); > > CREATE VIEW > ag_reach=> \d+ test_tmp > View "public.test_tmp" > Column | Type | Modifiers | Storage | Description > ----------+---------+-----------+---------+------------- > ?column? | integer | | plain | > View definition: > SELECT 1 > FROM l_payment_form > WHERE l_payment_form.payment_form_code::text = ANY (ARRAY['CREDIT_CARD'::character varying, 'OTHER'::character varying]::text[]); > > I wasn't very surprised by that.  But when I take the view definition as > stored in PG above, and create a new view: > > ag_reach=> CREATE VIEW test_tmp2 AS SELECT 1 FROM l_payment_form WHERE > l_payment_form.payment_form_code::text = ANY > > (ARRAY['CREDIT_CARD'::character varying, 'OTHER'::character varying]::text[]); > > CREATE VIEW > > ag_reach=> \d+ test_tmp2 > View "public.test_tmp2" > Column | Type | Modifiers | Storage | Description > ----------+---------+-----------+---------+------------- > ?column? | integer | | plain | > View definition: > SELECT 1 > FROM l_payment_form > WHERE l_payment_form.payment_form_code::text = ANY (ARRAY['CREDIT_CARD'::character varying::text, 'OTHER'::character varying::text]); > >  you'll see it now casts the individual array elements to text, rather > than the whole array as in test_tmp. Which is where it stops from my test: CREATE VIEW cp_view AS (SELECT 1 FROM cell_per WHERE season IN ('annual', 'perennial')); View "public.cp_view" Column | Type | Collation | Nullable | Default | Storage | Description ----------+---------+-----------+----------+---------+---------+------------- ?column? | integer | | | | plain | View definition: SELECT 1 FROM cell_per WHERE cell_per.season::text = ANY (ARRAY['annual'::character varying, 'perennial'::character varying]::text[]); CREATE VIEW cp_view AS (SELECT 1 FROM cell_per WHERE cell_per.season::text = ANY (ARRAY['annual'::character varying, 'perennial'::character varying]::text[])); View "public.cp_view" Column | Type | Collation | Nullable | Default | Storage | Description ----------+---------+-----------+----------+---------+---------+------------- ?column? | integer | | | | plain | View definition: SELECT 1 FROM cell_per WHERE cell_per.season::text = ANY (ARRAY['annual'::character varying::text, 'perennial'::character varying::text]); CREATE VIEW cp_view AS (SELECT 1 FROM cell_per WHERE cell_per.season::text = ANY (ARRAY['annual'::character varying::text, 'perennial'::character varying::text])); View "public.cp_view" Column | Type | Collation | Nullable | Default | Storage | Description ----------+---------+-----------+----------+---------+---------+------------- ?column? | integer | | | | plain | View definition: SELECT 1 FROM cell_per WHERE cell_per.season::text = ANY (ARRAY['annual'::character varying::text, 'perennial'::character varying::text]); Seems to be simplifying down to an end point. > > This doesn't impair the view's functionality, so I can't necessarily > complain.  But it does make it harder for me to know if the views were > recreated correctly.  I'd be curious to know what is going on here, and > if there's any way to avoid this behavior. The only way I can think of to maintain a consistent definition is to always create the view from the original definition: CREATE VIEW test_tmp AS (SELECT 1 FROM l_payment_form WHERE payment_form_code IN ('CREDIT_CARD','OTHER')); > > Thanks! > > Ken > > -- > AGENCY Software > A Free Software data system > By and for non-profits > /http://agency-software.org// > /https://demo.agency-software.org/client/ > ken.tanzer@agency-software.org > (253) 245-3801 > > Subscribe to the mailing list >  to > learn more about AGENCY or > follow the discussion. -- Adrian Klaver adrian.klaver@aklaver.com