Fixing pg custom queries and substituting ad_table for list template.