Replace insert-values with a select query for postgresql <= 8.1

Returning support was not added until PostgreSQL 8.2. This code has instead
been modified to fake it for PostgreSQL 8.1 by doing an SQL query on the
data in question after inserting.

This concept is known as RETURNING and was added in 8.2 as documented
in E.24.1 of the 8.2 guide:

    http://www.postgresql.org/docs/8.2/static/release-8-2.html

Signed-off-by: Ken Barber <ken@bob.sh>