Re: FUNCTIONs and CASTs

From: "Dean Gibson (DB Administrator)" <postgresql(at)ultimeth(dot)com>
To: pgsql-sql <pgsql-sql(at)postgresql(dot)org>
Subject: Re: FUNCTIONs and CASTs
Date: 2008-02-16 00:45:58
Message-ID: 47B63246.9070104@ultimeth.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On 2008-02-15 15:03, Dean Gibson (DB Administrator) wrote:
> On 2008-02-15 14:32, Tom Lane wrote:
>
> Casing a TEXT item to a CHAR( 9 ) item isn't a no-op. I've seen this
> before in "EXPLAIN ..." output, where a search on an indexed column
> will be sequential because the planner treats the search value as TEXT
> rather than CHAR( 9 ).
>
> Are you saying that no one believes there is a performance
> difference? Amazing ...
>
> Tom, I've privately eMailed you access instructions to one of my DB
> servers, so you can see for yourself.
>

OK, it must have been late at 2am when I last ran the tests, as it now
seems to work. By "work", I mean that the casting in the function body
is (in the particular case I was having an issue with) apparently
unnecessary if the types are proper (which includes the
table.column%TYPE notation).

I'm happy to find that out, since now I can use the table.column%TYPE
notation to advantage.

What helped confuse me is that the following function apparently DOES
need an internal cast:

CREATE OR REPLACE FUNCTION zzz( aaa CHAR(1) ) RETURNS CHAR(1) LANGUAGE
SQL AS 'SELECT $1';

SELECT zzz( 'abc' );

returns "abc", not "a". Apparently declarations of CHAR(n) are treated
as BPCHAR in function prototypes???

-- Dean

--
Mail to my list address MUST be sent via the mailing list.
All other mail to my list address will bounce.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Bryce Nesbitt 2008-02-16 04:32:00 Re: Backward compatibility psql 8.1 to 8.2
Previous Message Dean Gibson (DB Administrator) 2008-02-15 23:03:02 Re: FUNCTIONs and CASTs