Forum OpenACS Q&A: trunc() function causing errors

Collapse
Posted by Tom Jackson on

Several database queries require the trunc() function as well as the power() function. Do these exist somewhere? I'm using ACS3.2b2 and PostgreSQL 7.0 on AOLserver 3.0rc1.

Collapse
Posted by Ben Adida on
the power() function has changed to pow(). The trunc() function should be mostly covered by the postgres.sql-defined trunc(), but sometimes you have to port that function using date_trunc().
Collapse
Posted by Tom Jackson on

Here is what I did to make the errors go away. I don't know if this is the best solution or not. For the missing power(x,y) function, there were actually two problems. The new function is called pow(x,y), and ACS passes integer values.

drop function power(int4,int4); create function power(int4,int4) returns float8 as ' declare this_power alias for $1; this_base alias for $2; base_as_float float8; power_as_float float8; return_what float8; BEGIN base_as_float := float8(this_base); power_as_float := float8(this_power); return_what := pow(power_as_float,base_as_float); return return_what; END; ' language 'plpgsql';

Several other similar problems were solved by the following functions:

drop function trunc(int4); create function trunc(int4) returns integer as ' declare my_int alias for $1; BEGIN return my_int ; END; ' language 'plpgsql'; drop function round(int4); create function round(int4) returns integer as ' declare my_int alias for $1; int_as_float float8; BEGIN int_as_float := float8(my_int); return round(int_as_float); END; ' language 'plpgsql';

It seems like the last could be solved like the first like this:

drop function round(int4); create function round(int4) returns integer as ' declare my_int alias for $1; BEGIN return my_int; END; ' language 'plpgsql';

Please put me on the right track it these are worthless ideas!