title: Postgres RFC3339 datetime formatting
body: <p>Is there any way to format datetime to <code>RFC3339Nano</code> Eg: <code>2006-01-02T15:04:05.999999999Z07:00</code>  in postgres 9.3 or 9.5?</p>
  
  <p>I tried with <code>to_char</code>. But there is no documentation how to handle  <code>T</code>, <code>Z</code>, <code>+07:00</code>, <code>-07:00</code> etc.</p>
  
  <p>The nearest one I can reach is </p>
  
  <pre><code>v2=# select to_char(current_timestamp, 'YYYY-MM-DD HH:MI:SS.MSOF');
            to_char
  ----------------------------
   2016-05-08 12:16:14.493+04
  </code></pre>
  
  <p>Which is default JSON output format datetime in postgres 9.3. Please see below.</p>
  
  <pre><code>psql (9.5.1, server 9.3.6)
  Type "help" for help.
  
  fetchrdb=&gt; select to_json(current_timestamp);
               to_json
  ---------------------------------
   "2016-05-08 11:58:04.844548+04"
  (1 row)
  </code></pre>
  
  <p>In the case of JSON encoded output from postgres 9.5 is <code>RFC3339Nano</code> eg:</p>
  
  <pre><code>psql (9.5.1)
  Type "help" for help.
  
  v2=# select to_json(current_timestamp);
                to_json
  ------------------------------------
   "2016-05-08T11:59:17.121411+04:00"
  </code></pre>
  
  <p>I could't  find an option to format datetime to RFC3339Nano in postgres 9.3 or 9.5 using <code>to_char</code>.</p>
  
  <p><a href="http://www.postgresql.org/docs/9.5/static/functions-formatting.html" rel="noreferrer">http://www.postgresql.org/docs/9.5/static/functions-formatting.html</a></p>
  
  <p>Is there any hidden option/functions you use to achieve the same? Any help regarding is appreciated. </p>