title: Why do postgres foreign keys have to be the last column in the table?
body: <p>This works:</p>
  <pre><code>CREATE TABLE scans 
  (
      id BIGSERIAL NOT NULL PRIMARY KEY,
      ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
      started TIMESTAMP WITH TIME ZONE,
      finished TIMESTAMP WITH TIME ZONE,
      target_id INTEGER NOT NULL  
          REFERENCES targets ON UPDATE CASCADE
  );
  </code></pre>
  <p>but this:</p>
  <pre><code>CREATE TABLE scans 
  (
      id BIGSERIAL NOT NULL PRIMARY KEY,
      ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
      started TIMESTAMP WITH TIME ZONE,
      target_id INTEGER NOT NULL 
          REFERENCES targets ON UPDATE CASCADE,
      finished TIMESTAMP WITH TIME ZONE
  );
  </code></pre>
  <p>fails with the error:</p>
  <blockquote>
  <p>ERROR:  syntax error at or near &quot;TIMESTAMP&quot;<br />
  LINE 6: SET finished TIMESTAMP WITH TIME ZONE</p>
  </blockquote>
  <p>If I change the lines around further, the error is always at the column-type on the line below the foreign key. Making the foreign key the last column works around the issue.</p>
  <p>Why is this?</p>