1. A computer-implemented method for inferring types of database queries, the method comprising: accessing a program with one or more queries to a database that contains relations described by at least one database schema; receiving the database schema and at least one type hierarchy for the database; inferring types from definitions in the program by replacing each use of a database relation in the program by the types in the database schema; and generating a new program including the types that have been inferred with the new program only accessing unary relations in the database.