When is an explicit cast necessary? - Mailing list pgsql-general

From Alan Millington
Subject When is an explicit cast necessary?
Date
Msg-id 608787.2616.qm@web25408.mail.ukl.yahoo.com
Whole thread Raw
Responses Re: When is an explicit cast necessary?  (Greg Smith <greg@2ndquadrant.com>)
List 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?
 

pgsql-general by date:

Previous
From: Raymond O'Donnell
Date:
Subject: Re: Unable to uninstall postgres from Add/Remove programs
Next
From: Dimitri Fontaine
Date:
Subject: Re: Fuzzy string matching of product names