Re: help with query!!! - Mailing list pgsql-sql

From Tom Lane
Subject Re: help with query!!!
Date
Msg-id 2619.1050363285@sss.pgh.pa.us
Whole thread Raw
In response to help with query!!!  ("mdc@keko.com.ar" <mdc@keko.com.ar>)
List pgsql-sql
"mdc@keko.com.ar" <mdc@keko.com.ar> writes:
>  numeroVia       | smallint                    | not null
>  fechaHora       | timestamp(3) with time zone | not null

> explain delete from "Transitos"
> where "codigoEstacion"= '02' and
> "numeroVia" = 1 and
> "fechaHora" = '2003-0403 17:34:06.92'::timestamp and
> "medioPago" = 'Efectivo' and
> "tipoTransito"= 'Normal' and
> categoria='01'

You're casting the constant compared to fechaHora to timestamp, which is
the wrong thing (timestamp != timestamp with timezone); and you're not
casting the constant compared to numeroVia to smallint.  Each of these
type mismatches will prevent an indexscan.

If I were you I'd declare numeroVia as int, not smallint, because you're
getting no space savings from smallint anyway.  Then you could just
write

delete from "Transitos"
where "codigoEstacion"= '02' and
"numeroVia" = 1 and
"fechaHora" = '2003-0403 17:34:06.92' and
"medioPago" = 'Efectivo' and
"tipoTransito"= 'Normal' and
categoria='01'

and it should do what you want.
        regards, tom lane



pgsql-sql by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: help with query!!!
Next
From: "Sigi Jekabsons"
Date:
Subject: fast case-insensitive sort