Re: Cross-datatype Comparisons and Indexes - Mailing list pgsql-general

From Tom Lane
Subject Re: Cross-datatype Comparisons and Indexes
Date
Msg-id 2541.1093036141@sss.pgh.pa.us
Whole thread Raw
In response to Re: Cross-datatype Comparisons and Indexes  (Bruno Wolff III <bruno@wolff.to>)
Responses Re: Cross-datatype Comparisons and Indexes  ("Joshua D. Drake" <jd@commandprompt.com>)
List pgsql-general
Bruno Wolff III <bruno@wolff.to> writes:
>   "Thomas F.O'Connell" <tfo@sitening.com> wrote:
>> Since the current stable version of postgres (7.4.x) doesn't allow
>> cross-datatype comparisons of indexes, is it always necessary to cast
>> my application data explicitly in order for an index to be used, even
>> among the integer types?

> Yes.

I can think of at least three workarounds in 7.4:

1. Always quote your constants:

    ... WHERE bigintcol = '42';

2. Use a prepared statement:

    PREPARE foo(bigint) AS ... WHERE bigintcol = $1;

    EXECUTE foo(42);

3. Use parameterized statements in extended-query mode (essentially the
   same idea as #2, but at the protocol level).  This doesn't help for
   pure SQL scripts, but is very workable when coding against libpq or
   JDBC.  Among other things it gets you out of worrying about SQL
   injection attacks when your parameter values come from untrusted
   sources.

            regards, tom lane

pgsql-general by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: 8.0 release schedule?
Next
From: "Joshua D. Drake"
Date:
Subject: Re: Cross-datatype Comparisons and Indexes