> Can I somehow get the total number of rows in
> a function?
create function numRows() returns int4
as 'select count(*) from <table>'
language 'sql';
> select var1, count(*) / numRows() * 100 from table1 group by var1;
maybe this is better
select var1, (count(*) * 100) / numRows() from table1 group by var1;