Re: A question on systable_beginscan()

From: Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>
To: Onder Kalaci <onder(at)citusdata(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: A question on systable_beginscan()
Date: 2016-03-28 10:09:43
Message-ID: 56F902E7.1040200@lab.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Hi,

On 2016/03/25 23:49, Onder Kalaci wrote:
> Hi hackers,
>
> As it's documented in the source code, systable_beginscan() could be used
> to on non-system tables as well. My question is that, is it possible to
> write a C code with systable_beginscan(), systable_getnext() and ScanKeys
> which is equivalent to the following query: (Assume that the qual_column is
> a text column)
>
> SELECT id FROM table WHERE qual_column::int = 15;
>
> In other words, can we cast a column type to another type via these
> low-level APIs? Are there any examples in the Postgres source?

Don't think the API advertises any support for that or at least I couldn't
find any. However, I am not sure if it's outright impossible to achieve
that with some prep - <uglyhack> initialize the scan key (sk_func) with
FmgrInfo of a specialized function, that performs the cast before
comparing. Such a function would be written to work with fixed pair of
source and target types to be able to invoke, say, textout() -> int4in(),
before comparing the value with the argument (sk_argument). The argument
would have to be of the target type, needless to say </uglyhack>. Most
likely, this would be an unrecommended course of action in the long run,
so you would be better off considering other ways (like SPI).

Thanks,
Amit

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Kellerer 2016-03-28 10:36:10 Re: Draft release notes for next week's releases
Previous Message Etsuro Fujita 2016-03-28 10:09:06 Re: Postgres_fdw join pushdown - INNER - FULL OUTER join combination generating wrong result