title: dynamic sql query in postgres
body: <p>I was attempting to use Dynamic SQL to run some queries in postgres.</p>
  
  <p>Example:</p>
  
  <pre><code>EXECUTE format('SELECT * from result_%s_table', quote_ident((select id from ids where condition = some_condition)))
  </code></pre>
  
  <p>I have to query a table, which is of the form result_%s_table wherein, I need to substitute the correct table name (an id) from an another table. </p>
  
  <p>I get the error <code>ERROR:  prepared statement "format" does not exist</code></p>
  
  <p>Link: <a href="https://stackoverflow.com/questions/12777231/string-substitution-with-query-result-postgresql">string substitution with query result postgresql</a></p>