Re: Slow UPADTE, compared to INSERT - Mailing list pgsql-performance

From Richard Huxton
Subject Re: Slow UPADTE, compared to INSERT
Date
Msg-id 200312051323.43966.dev@archonet.com
Whole thread Raw
In response to Re: Slow UPADTE, compared to INSERT  (Shridhar Daithankar <shridhar_daithankar@persistent.co.in>)
Responses Re: Slow UPADTE, compared to INSERT
List pgsql-performance
On Friday 05 December 2003 12:49, Shridhar Daithankar wrote:
> Ivar Zarans wrote:
> > It seems, that PyPgSQL query quoting is not aware of this performance
> > problem (to which Cristopher referred) and final query, sent to server
> > is correct SQL, but not correct, considering PostgreSQL bugs.

>
> Will following help?
>
> qry = "UPDATE table1 SET status = %s WHERE recid = '%s'"
> cursor.execute(qry, status, recid)

Better IMHO would be: "UPDATE table1 SET status = %s WHERE recid = %s::int8"

PG is very strict regarding types - normally a good thing, but it can hit you
unexpectedly in this scenario. The reason is that the literal number is
treated as int4, whereas quoted it is marked as type unknown. Unkown gets
cast to int8, whereas int4 gets left as-is. If you want to know why int4
doesn't get promoted to int8 automatically, browse the hackers list for the
last couple of years.

--
  Richard Huxton
  Archonet Ltd

pgsql-performance by date:

Previous
From: Ivar Zarans
Date:
Subject: Re: Slow UPADTE, compared to INSERT
Next
From: Shridhar Daithankar
Date:
Subject: Re: Slow UPADTE, compared to INSERT