pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
trying to do an update a bit confused.
4+ messages / 3 participants
[nested] [flat]

* trying to do an update a bit confused.
@ 2005-04-19 14:06 Joel Fradkin <jfradkin@wazagua.com>
  2005-04-19 23:03 ` Re: trying to do an update a bit confused. Jaime Casanova <systemguards@gmail.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Joel Fradkin @ 2005-04-19 14:06 UTC (permalink / raw)
  To: pgsql-sql

update tblcase  set merchandisetotal = 

(

COALESCE(( SELECT sum(m.quantity::numeric * m.amount) AS merchandiseamount

           FROM tblmerchandise m

          WHERE m.caseid = tblcase.caseid AND m.clientnum::text =
tblcase.clientnum::text), 0.0)

)

 

I tried running the above and it wants to do a sum on all the records in
tblcase instead of just the one being updated, what am I doing wrong?

 

Joel Fradkin

 

 

 

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: trying to do an update a bit confused.
  2005-04-19 14:06 trying to do an update a bit confused. Joel Fradkin <jfradkin@wazagua.com>
@ 2005-04-19 23:03 ` Jaime Casanova <systemguards@gmail.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Jaime Casanova @ 2005-04-19 23:03 UTC (permalink / raw)
  To: Joel Fradkin <jfradkin@wazagua.com>; +Cc: pgsql-sql

On 4/19/05, Joel Fradkin <jfradkin@wazagua.com> wrote:
>  
>  
> 
> update tblcase  set merchandisetotal = 
> 
> ( 
> 
> COALESCE(( SELECT sum(m.quantity::numeric * m.amount) AS merchandiseamount 
> 
>            FROM tblmerchandise m 
> 
>           WHERE m.caseid = tblcase.caseid AND m.clientnum::text =
> tblcase.clientnum::text), 0.0) 
> 
> ) 
> 
>   

Put the coalesce inside the select:
update tblcase  set merchandisetotal =  
    (SELECT COALESCE(sum(m.quantity::numeric * m.amount),0.0) AS
merchandiseamount
        FROM tblmerchandise m 
      WHERE m.caseid = tblcase.caseid AND m.clientnum::text =
tblcase.clientnum::text)

-- 
Regards,

DBA* Jaime Casanova
(DBA: DataBase Aniquilator ;)



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: trying to do an update a bit confused.
@ 2005-04-19 14:43 KÖPFERL Robert <robert.koepferl@sonorys.at>
  2005-04-19 16:57 ` Re: trying to do an update a bit confused. Joel Fradkin <jfradkin@wazagua.com>
  0 siblings, 1 reply; 4+ messages in thread

From: KÖPFERL Robert @ 2005-04-19 14:43 UTC (permalink / raw)
  To: pgsql-sql

You're most probably missing a Where clause after the parentensis. see:

-----Original Message-----
From: Joel Fradkin [mailto:jfradkin@wazagua.com]
Sent: Dienstag, 19. April 2005 16:06
To: pgsql-sql@postgresql.org
Subject: [SQL] trying to do an update a bit confused.



update tblcase  set merchandisetotal = 

(

COALESCE(( SELECT sum(m.quantity::numeric * m.amount) AS merchandiseamount

           FROM tblmerchandise m

          WHERE m.caseid = tblcase.caseid AND m.clientnum::text =
tblcase.clientnum::text), 0.0)

) 

WHERE <condtion that selects one record>;

 

 

I tried running the above and it wants to do a sum on all the records in
tblcase instead of just the one being updated, what am I doing wrong?

 

Joel Fradkin

 

 

 

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: trying to do an update a bit confused.
  2005-04-19 14:43 Re: trying to do an update a bit confused. KÖPFERL Robert <robert.koepferl@sonorys.at>
@ 2005-04-19 16:57 ` Joel Fradkin <jfradkin@wazagua.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Joel Fradkin @ 2005-04-19 16:57 UTC (permalink / raw)
  To: 'KÖPFERL Robert' <robert.koepferl@sonorys.at>; pgsql-sql

I am not updating 1 record.

I have : WHERE m.caseid = tblcase.caseid AND m.clientnum::text =
tblcase.clientnum::text)

Which should do the aggregate on the record that is being updated (least as
I understood it).

It should update all record in case with either 0 if there are no
merchandise records or do a sum of the merch records for the case being
updated.

 

Joel

 

I also never heard back on the merge join issue (why do I need to specify
them off on one machine and it runs faster on the other).

I am guessing it is memory related and config related, but I am about to
give up on postgres as I am just not getting all my views to run fast
enough.

You guys could say my views are bad SQL design etc, but they run fine in
MSSQL. I don’t mind visiting each one to make them better, but I am just not
able to increase the speed on all of them. The last one about assoc finally
did run in 3 secs with merge joins off which is pretty fast, but now I have
others that seem pretty simple to me and yet run very slow. 

 

 

You're most probably missing a Where clause after the parentensis. see:

-----Original Message-----
From: Joel Fradkin [mailto:jfradkin@wazagua.com]
Sent: Dienstag, 19. April 2005 16:06
To: pgsql-sql@postgresql.org
Subject: [SQL] trying to do an update a bit confused.

update tblcase  set merchandisetotal = 

(

COALESCE(( SELECT sum(m.quantity::numeric * m.amount) AS merchandiseamount

           FROM tblmerchandise m

          WHERE m.caseid = tblcase.caseid AND m.clientnum::text =
tblcase.clientnum::text), 0.0)

) 

WHERE <condtion that selects one record>;

 

 

I tried running the above and it wants to do a sum on all the records in
tblcase instead of just the one being updated, what am I doing wrong?

 

Joel Fradkin

 

 

 

^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2005-04-19 23:03 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-04-19 14:06 trying to do an update a bit confused. Joel Fradkin <jfradkin@wazagua.com>
2005-04-19 23:03 ` Jaime Casanova <systemguards@gmail.com>
2005-04-19 14:43 Re: trying to do an update a bit confused. KÖPFERL Robert <robert.koepferl@sonorys.at>
2005-04-19 16:57 ` Joel Fradkin <jfradkin@wazagua.com>

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