Re: Weird type selection choice - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: Weird type selection choice
Date
Msg-id 20071107185602.GE21788@alvh.no-ip.org
Whole thread Raw
In response to Re: Weird type selection choice  (Peter Eisentraut <peter_e@gmx.net>)
List 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)


pgsql-hackers by date:

Previous
From: "Kevin Grittner"
Date:
Subject: Re: Visibility map thoughts
Next
From: Alvaro Herrera
Date:
Subject: Re: A small rant about coding style for backend functions