SPI_prepare for semi-unknown types - Mailing list pgsql-hackers

From Alex Pilosov
Subject SPI_prepare for semi-unknown types
Date
Msg-id Pine.BSO.4.10.10106220008300.29168-100000@spider.pilosoft.com
Whole thread Raw
Responses Re: SPI_prepare for semi-unknown types  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Is there a way to call SPI_prepare in case the precise datatype is not
known? 

Example, having a statement like 'select count(*) from foo where
fieldname=$1' where I know that $1 is a stringish type and it _should_ be
convertable using xxx_in (CString-to-datum conversion functions), however,
I do not know the precise type (could be name or varchar or text).

I understand that SPI_execute uses pg_parse_and_rewrite to do the actual
parsing and binding of function OIDs to the argument types. I'm looking at
transformExpr in parser/parse_expr.c, it seems to be the only place that
actually does it. 

There, I'm not sure how would it handle the case where paramtype is
specified as 'char', but it actually may need to be cast to 'text' for
execution. I guess I can find out by just trying it, just wanted to ask
first. :)

Ideally, I would like to be able to say "I don't know what this parameter
is like, treat it like it would be treated coming in a fully-formed query
(i.e. using CSTRING conversions)", but I'm not sure if its possible.

Thanks to anyone who can offer some help.

-alex



pgsql-hackers by date:

Previous
From: Tatsuo Ishii
Date:
Subject: Re: stuck spin lock with many concurrent users
Next
From: Olivier PRENANT
Date:
Subject: Re: psql+openssl+uniware7