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 1i8Vox-0000rL-GL for pgsql-general@arkaria.postgresql.org; Thu, 12 Sep 2019 20:36:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i8Vow-0002nY-Cy for pgsql-general@arkaria.postgresql.org; Thu, 12 Sep 2019 20:36:02 +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 1i8Vow-0002nR-34 for pgsql-general@lists.postgresql.org; Thu, 12 Sep 2019 20:36:02 +0000 Received: from mail-ot1-x336.google.com ([2607:f8b0:4864:20::336]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i8Vou-00012M-2J for pgsql-general@lists.postgresql.org; Thu, 12 Sep 2019 20:36:01 +0000 Received: by mail-ot1-x336.google.com with SMTP id b2so27355657otq.10 for ; Thu, 12 Sep 2019 13:35:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=TF6cpn6CeoI13z9hIAx3z1IWGtI5HzFcNNt4n2XbrxQ=; b=HHINuHFfxU7zJnOwRO/+BAy4YgX97DKyFduyUxoCG+0PiDSJ1TlHRkkHUW+V89vx2N 6W5MrCtRHHx6SibboRlURmG18FxfrfNC+W5rAZwtdHk6cxDle021AvUV+npogJxKom/U Q3Rx6Aarn5v0tV+WkijaXm0f3xAMiqylGHC0V+9RS7MGPfkFVjf3S+nGSQi5Lu5QXI9W X20CWnaGtRIbdTUc7SUfTwddH/JoLvMNBTZYY0gQwNeEJkiY9uup0whmx4pjS7RdSbgU MdSzig0SjZ8Nrqn3DLW0Jdf50S5kAc3HgVyYcLrRH4BTc9p6i9DmoBPoaZrPXVava3AG 633A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=TF6cpn6CeoI13z9hIAx3z1IWGtI5HzFcNNt4n2XbrxQ=; b=Z6YDfj+FLZsiGY7RbXWOeEEkISHFzQvDsHvg5EJGHe+OxtQlJU25frZ+0jPBNZJODh 786onfRcGLmCk5MihboFx0m5AXBg4bKSLUsVJGT87FMWll1MNJ2/ZNDgQ8EqbAdSbD0g jcwIAK+4CraFsbEorLeD4xfTZ7Ns0Hh58bAeERnMF6V4dbpgAUg8JjF2Y008vKFgwRl1 xM8GEktE8MxQL+xTGLKV0FueLm0y8bv9ZpFo3x1P0U9CEG0HOJDY8+WZyX8/azJCteZu MTe3uHUKlLgKacm57VI7+5ofLZ/qB4aC3C6tF2LryBDGZ9LUaSpz4V/dDMN6dx9aJ7J8 ebOA== X-Gm-Message-State: APjAAAULnoaU/tskPvRDhaTDd0erOOzVGOqJ7/UZnemaAvPp+oGIeYQ7 FQSwUVVAzaqKoL0zxN1WV1bc0XjF++MpvA== X-Google-Smtp-Source: APXvYqzZSa0TOZ/e+afloY3KAePx/SftqMp4IHYmj+8TzCxrJgXMs2h2rHCWvuY9uMUQB8wqzhby7Q== X-Received: by 2002:a05:6830:12d1:: with SMTP id a17mr3789795otq.40.1568320558069; Thu, 12 Sep 2019 13:35:58 -0700 (PDT) Received: from [192.168.1.10] (ip70-186-126-197.no.no.cox.net. [70.186.126.197]) by smtp.googlemail.com with ESMTPSA id 36sm9589188ott.66.2019.09.12.13.35.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Sep 2019 13:35:57 -0700 (PDT) Subject: Re: Referncing a calculated column in a select? To: pgsql-general@lists.postgresql.org References: <20190912192329.GA21150@panix.com> From: Ron Message-ID: <9a55a78e-6a9d-b8a0-d9c8-f5a6fbc6fcea@gmail.com> Date: Thu, 12 Sep 2019 15:35:56 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190912192329.GA21150@panix.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 9/12/19 2:23 PM, stan wrote: > I am creating some views, that have columns with fairly complex calculations > in them. The I want to do further calculations using the result of this > calculation. Right now, I am just duplicating the first calculation in the > select fro the 2nd calculated column. There must be a batter way to do > this, right? I must be misunderstanding you, because you can just do more of what you're doing now. Here's an example of doing some calculations in the creation of the view, and then more calculations when selecting from the view: test=# create table gargle (i integer, j integer); CREATE TABLE test=# create view v_gargle (i1, j1) as select i*2, j*3 from gargle; CREATE VIEW test=# select * from v_gargle;  i1 | j1 ----+----   4 |  9 (1 row) test=# select i1 - 3, j1 * 8 from v_gargle;  ?column? | ?column? ----------+----------         1 |       72 -- Angular momentum makes the world go 'round.