Dump the points, get the average?
create table g ( id integer, geom geometry );
insert into g values (1, 'LINESTRING(0 0 0, 1 1 1, 2 2 2)');
insert into g values (2, 'LINESTRING(1 1 1, 2 2 2, 3 3 3)');
with pts as (
select id,
st_z((st_dumppoints(geom)).geom) as z
from g
)
select avg(z), id
from pts
group by id;
Or in subquery form, if you don't like CTEs:
select avg(z), id
from (
select id,
st_z((st_dumppoints(geom)).geom) as z
from g
) as pts
group by id;
Trouble with this is that it's a vertex average, it doesn't account for the parts of the line in between the vertices, so the vertex density at particular locations will skew the average in favour of those locations. A more sophisticated result would require some quite complicated PL/PgSQL code.