| From: | Alvaro Herrera <alvherre(at)commandprompt(dot)com> | 
|---|---|
| To: | Peter Eisentraut <peter_e(at)gmx(dot)net> | 
| Cc: | Heikki Linnakangas <heikki(at)enterprisedb(dot)com>, pgsql-hackers(at)postgresql(dot)org | 
| Subject: | Re: Weird type selection choice | 
| Date: | 2007-11-07 18:56:02 | 
| Message-ID: | 20071107185602.GE21788@alvh.no-ip.org | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-hackers | 
Peter Eisentraut wrote:
> Am Mittwoch, 7. November 2007 schrieb Heikki Linnakangas:
> > Peter Eisentraut wrote:
> > > I wrote:
> > >> I noticed this problem in 8.2 and 8.3:
> > >>
> > >> pei=# select mod( trunc( 1 ), 2 );
> > >> ERROR:  42883: function mod(double precision, integer) does not exist
> > >> LINE 1: select mod( trunc( 1 ), 2 );
> > >>                ^
> > >
> > > I suppose there will be little interest in including the obvious
> > > solution, namely
> > >
> > > CREATE FUNCTION pg_catalog.trunc(int) RETURNS int AS $$ SELECT $1; $$
> > > LANGUAGE SQL STRICT IMMUTABLE;
> >
> > It does sound totally useless...
> >
> > Why would you run a query like that in the first place? It seems like a
> > useless query as it is. Is there a bigger story behind it?
> 
> The "1" is substituted from somewhere else.  If the value happens to be, say, 
> 1.5, it works, but not with 1 or 2.
Maybe as a workaround these are useful:
alvherre=# select mod( trunc( 1.0 ), 2 );
 mod 
-----
   1
(1 fila)
alvherre=# select mod( trunc( 1::numeric ), 2 );
 mod 
-----
   1
(1 fila)
-- 
Alvaro Herrera       Valdivia, Chile   ICBM: S 39º 49' 18.1", W 73º 13' 56.4"
Bob [Floyd] used to say that he was planning to get a Ph.D. by the "green
stamp method," namely by saving envelopes addressed to him as 'Dr. Floyd'.
After collecting 500 such letters, he mused, a university somewhere in
Arizona would probably grant him a degree.              (Don Knuth)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Alvaro Herrera | 2007-11-07 19:05:15 | Re: A small rant about coding style for backend functions | 
| Previous Message | Kevin Grittner | 2007-11-07 18:20:12 | Re: Visibility map thoughts |