create table based on select query postgresql