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 1gZIQS-0001rv-RQ for pgsql-general@arkaria.postgresql.org; Tue, 18 Dec 2018 16:40:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gZIQR-00084r-HO for pgsql-general@arkaria.postgresql.org; Tue, 18 Dec 2018 16:40:55 +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 1gZIPx-0004E2-Jk for pgsql-general@lists.postgresql.org; Tue, 18 Dec 2018 16:40:25 +0000 Received: from mail-oi1-x243.google.com ([2607:f8b0:4864:20::243]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gZIPv-0006cU-Ds for pgsql-general@lists.postgresql.org; Tue, 18 Dec 2018 16:40:25 +0000 Received: by mail-oi1-x243.google.com with SMTP id x23so2472589oix.3 for ; Tue, 18 Dec 2018 08:40:22 -0800 (PST) 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=A6D4j4cxHX2Rn1i4KCNLGkCbkfmimCdnKDlPK6HdxgA=; b=crTD7SKnMIRYq81Fn2cFFQFQxtNhBRNwSRtutbU04tcduJR4DApRoad11LqxK7A/r2 BS2ahNA/nrjuY7hYSJMCbuwWetnC6yFrkqOhZD6leB83qOWoPQMF1QXbTWB2HIQmEuwQ DjMYAUhYMMVxFpBwZ9mzNg0hvCRZwmlfYWJNp5GHrT1z/rc1pYPCiY/ckYhCaloQJzey WCE3OrlYsKggW1rYyYWkzrborllE4e1+43R6wFA+h6ldTXWvj/oYmDfZzvNR8cS1uh+w XVS4rgrqTHsbY+Kb09Z+y/ZXewxk9G2Z7Ohy81JsjSRiRbRfxuO9fXrIrSqZMittlIsd OQ3g== 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=A6D4j4cxHX2Rn1i4KCNLGkCbkfmimCdnKDlPK6HdxgA=; b=XOTA8j2jrboRrlVlO9BMSJ4OvyKabBIQG3y7dZQVWsp6SCd8EH0x9RYKwV3BAI9fhg i5OGd/2xW6aL5T5W7i+rvZqgIChKAyVYow4z2/XLtmH4x8hJJBeJOm56BrI1ubP+UiSC swSDV8SjtrRo/EGJE+BQ4aYGUje8A71ZebtsH/C1QCSUVBHT7TjI0xndp9Cifd8DcWkx mJwT81fEvcVRYpc+QxQi7amht995BuFMdoo1IzfB+C/uuOcC9MM9OooNP+wP/qamKu/i IOKa8z7CMTIOHR8L8aAjqxBeUDwJosIU+hCILpb1qEIII4BTQ+5MvrLK+tJvhbtDmqQM OaoA== X-Gm-Message-State: AA+aEWZwcNmGvpNQ9OnVgX+A/gfd7jzi/iap1bSAGEAzl5pAInfxFFB5 +gMJhcig3n7VPwbqo+hMnzs0tcg5 X-Google-Smtp-Source: AFSGD/VpEGlMCrzQB9ghPCnia+pkrW0/CDOn1EOCY2lq6yK+g1Btss+Z8e574thbLF/GfZTY2Rp4tA== X-Received: by 2002:aca:b388:: with SMTP id c130mr7774938oif.123.1545151220568; Tue, 18 Dec 2018 08:40:20 -0800 (PST) Received: from [192.168.1.10] (ip70-171-116-89.no.no.cox.net. [70.171.116.89]) by smtp.googlemail.com with ESMTPSA id 99sm7873475oth.20.2018.12.18.08.40.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Dec 2018 08:40:19 -0800 (PST) Subject: Re: Format an Update with calculation To: pgsql-general@lists.postgresql.org References: <1545117297.4397.18.camel@dell990-bret-centos.localdomain> <1545148273.3724.2.camel@dell990-bret-centos.localdomain> From: Ron Message-ID: Date: Tue, 18 Dec 2018 10:40:19 -0600 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: <1545148273.3724.2.camel@dell990-bret-centos.localdomain> 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 Bret, That's just an example of how to use Postgres' cast syntax.  You'd write: UPDATE im_ci_item_transfer    SET suggested_retail_price=(suggested_retail_price + (suggested_retail_price * .13))::numeric(7,2) WHERE item_code='0025881P2'; I prefer the round() function, though. On 12/18/2018 09:51 AM, Bret Stern wrote: > Thanks again, > I don't remember ever using a select in an update. > Not sure how to use a select in an update, I'll google around. > > > On Tue, 2018-12-18 at 08:18 +0100, Pavel Stehule wrote: >> >> >> út 18. 12. 2018 v 8:15 odesílatel Bret Stern >> napsal: >> >> My statement below updates the pricing no problem, but I want >> it to be >> formatted with 2 dec points eg (43.23). >> >> Started playing with to_numeric but can't figure it out. Lots >> of examples with to_char in the >> manual, but still searching for answer. >> >> Can it be done? >> >> >> >> postgres=# select random(); >> ┌───────────────────┐ >> │ random │ >> ╞═══════════════════╡ >> │ 0.261391982901841 │ >> └───────────────────┘ >> (1 row) >> >> postgres=# select random()::numeric(7,2); >> ┌────────┐ >> │ random │ >> ╞════════╡ >> │ 0.67 │ >> └────────┘ >> (1 row) >> >> >> >> Regards >> >> >> Pavel >> >> >> >> I want suggested_retail_price to be formatted to 2 decimal >> points >> >> UPDATE im_ci_item_transfer >> SET suggested_retail_price=(suggested_retail_price + >> (suggested_retail_price * .13)) >> WHERE item_code='0025881P2'; >> >> Feeling lazy, sorry guys > > -- Angular momentum makes the world go 'round.