Обсуждение: CHAR vs TEXT args
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
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
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);
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