pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Format an Update with calculation
Date: Tue, 18 Dec 2018 10:40:19 -0600
Message-ID: <a6d4bdea-4cc1-2728-7ce4-5135a41f6428@gmail.com> (raw)
In-Reply-To: <1545148273.3724.2.camel@dell990-bret-centos.localdomain>
References: <1545117297.4397.18.camel@dell990-bret-centos.localdomain>
	<CAFj8pRD76ZjhYe5fAFv4iVC+vCJ4QE8jnrcd2ygUmnDZzcEkng@mail.gmail.com>
	<1545148273.3724.2.camel@dell990-bret-centos.localdomain>

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
>> <bret_stern@machinemanagement.com> 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.




view thread (9+ messages)  latest in thread

Message-ID: <a6d4bdea-4cc1-2728-7ce4-5135a41f6428@gmail.com>
Permalink:  ../a6d4bdea-4cc1-2728-7ce4-5135a41f6428@gmail.com/
Also on:    postgresql.org/message-id/a6d4bdea-4cc1-2728-7ce4-5135a41f6428@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: ronljohnsonjr@gmail.com
  Subject: Re: Format an Update with calculation
  In-Reply-To: <a6d4bdea-4cc1-2728-7ce4-5135a41f6428@gmail.com>
  References: <1545117297.4397.18.camel@dell990-bret-centos.localdomain> <CAFj8pRD76ZjhYe5fAFv4iVC+vCJ4QE8jnrcd2ygUmnDZzcEkng@mail.gmail.com> <1545148273.3724.2.camel@dell990-bret-centos.localdomain> <a6d4bdea-4cc1-2728-7ce4-5135a41f6428@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox