Обсуждение: CHAR vs TEXT args

Поиск
Список
Период
Сортировка

CHAR vs TEXT args

От
david_shadovitz@xontech.com (David Shadovitz)
Дата:
I've created two PL/pgSQL functions with the same name and different
signatures:

CREATE FUNCTION ABC(CHAR) ...
CREATE FUNCTION ABC(TEXT) ....

I intended to call the CHAR-signature function like this:
SELECT ABC('R');

And the TEXT-signature function like this:
SELECT ABC('Right');

But I found that both calls invoke the TEXT-signature function.  So is
there any distinction between CHAR and TEXT?  Can I somehow specify
that the argument 'R' is to be treated as a CHAR, so the
CHAR-signature version of ABC is executed?

Thanks.
-David

Re: CHAR vs TEXT args

От
Joe Conway
Дата:
David Shadovitz wrote:
> I intended to call the CHAR-signature function like this:
> SELECT ABC('R');
>
> And the TEXT-signature function like this:
> SELECT ABC('Right');
>
> But I found that both calls invoke the TEXT-signature function.  So is
> there any distinction between CHAR and TEXT?  Can I somehow specify
> that the argument 'R' is to be treated as a CHAR, so the
> CHAR-signature version of ABC is executed?

If you want to force the CHAR version, do something like:
   SELECT ABC('R'::char);

See:
http://www.postgresql.org/docs/view.php?version=7.3&idoc=0&file=sql-expressions.html#SQL-SYNTAX-TYPE-CASTS

HTH,

Joe


Re: CHAR vs TEXT args

От
Dennis Gearon
Дата:
David Shadovitz wrote:

>I've created two PL/pgSQL functions with the same name and different
>signatures:
>
>CREATE FUNCTION ABC(CHAR) ...
>CREATE FUNCTION ABC(TEXT) ....
>
>I intended to call the CHAR-signature function like this:
>SELECT ABC('R');
>
>And the TEXT-signature function like this:
>SELECT ABC('Right');
>
>But I found that both calls invoke the TEXT-signature function.
>

maybe you need to do this:

SELECT ABC('R':TEXT);
SELECT ABC('Right':CHAR);




Re: CHAR vs TEXT args

От
david_shadovitz@xontech.com (David Shadovitz)
Дата:
Thanks, Joe and Dennis.

That double-colon type cast did the trick.

As an experienced software engineer, but a newcomer to PostgreSQL, I
appreciate the help.

-David