title: How to create sequence using starting value from query?
body: <p>In database migration script (psql) I want to create sequence starting from certain value queried from table, like:</p>
  
  <pre><code>CREATE SEQUENCE book_id_seq START ( SELECT MAX(id) + 1 FROM book.book );
  </code></pre>
  
  <p>or tried to set <code>\set start (SELECT MAX(id) + 1 FROM book.book)</code> to use variable like:</p>
  
  <pre><code>CREATE SEQUENCE book_id_seq START :'start';
  </code></pre>
  
  <p>But using <code>\set</code> did not inerpret the query. </p>
  
  <p>Another way setting variable did not work also</p>
  
  <pre><code>start := SELECT MAX(id) + 1 FROM book.book;
  </code></pre>
  
  <p>gave error:</p>
  
  <pre><code>ERROR:  syntax error at or near ":="
  LINE 1: start := SELECT MAX(id) + 1 FROM book.book;
  </code></pre>
  
  <p>Selecting value INTO does not help also, because accessing needs another SELECT query. </p>
  
  <p>Using static value works fine:</p>
  
  <pre><code>\set start 33
  CREATE SEQUENCE book_id_seq START :'start'::int;
  </code></pre>
  
  <p>How to use dynamic starting value?</p>
  
  <p>Postgres 9.6</p>