When is an explicit cast necessary?

From: Alan Millington <admillington(at)yahoo(dot)co(dot)uk>
To: Postgres general mailing list <pgsql-general(at)postgresql(dot)org>
Subject: When is an explicit cast necessary?
Date: 2010-04-09 10:46:37
Message-ID: 608787.2616.qm@web25408.mail.ukl.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I am using Postgres 8.4.1 on Windows XP Professional Service Pack 3.
 
I have a PL/pgSQL function which is defined as "returns record". The record contains three values. In one execution path, the values are read from a table, the selected columns being of types int, smallint and char(1). In another execution path, the second and third values are the literals 1 and 'R'. In the original version of the function the assignment in the second case was as follows:
 
   v_rv = (v_id, 1, 'R') ;

where v_rv is a variable of type record, and v_id is of type int. The client application calls the function as follows:
 
   select col1, col2, col3 from func(?, ?, ?) as (col1 int, col2 smallint, col3 char(1))
 
As far as I remember, when I was using Postgres 8.1.4 that worked, but under Postgres 8.4.1 it results in the errors "Returned type integer does not match expected type smallint" and "Returned type unknown does not match expected type character". I can avoid the error by altering the assignment thus:
 
   v_rv = (v_id, 1::smallint, 'R'::char(1)) ;

but I am puzzled as to why these explicit casts should be necessary. Is this covered anywhere in the documentation?
 

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Dimitri Fontaine 2010-04-09 13:47:19 Re: Fuzzy string matching of product names
Previous Message Raymond O'Donnell 2010-04-09 10:30:40 Re: Unable to uninstall postgres from Add/Remove programs