Fixed bugs in PostgreSQL construction of RTI tables.