title: How can I read a timestamp with timezone (timestamptz) value from PostgreSQL in Rust?
body: <p>What's the right Rust data type to use for a <code>timestamptz</code> when using postgres version 0.17.0 with Rust 1.40.0?</p>
  
  <p>I read the docs for <a href="https://docs.rs/postgres/0.17.0/postgres/types/enum.Timestamp.html" rel="nofollow noreferrer"><code>Timestamp</code></a> but have no idea what this means or how to implement it.</p>
  
  <p>The <a href="https://crates.io/crates/postgres/0.17.0-alpha.1" rel="nofollow noreferrer">readme for 0.17.0-alpha.1</a> has a table which says that <code>timezone</code> corresponds to Rust types  <code>time::Timespec</code> or <code>chrono::DateTime&lt;Utc&gt;</code> but neither works for me.</p>
  
  <p>When I try to use the stipulated features in my Cargo.toml using:</p>
  
  <pre><code>[dependencies]
  postgres = {version="0.17.0-alpha.1", features=["with-chrono", "with-time"]}
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre class="lang-none prettyprint-override"><code>the package `mypackage` depends on `postgres`, with features: `with-time, with-chrono` but `postgres` does not have these features.
  </code></pre>
  
  <hr>
  
  <p>Here's some functional code and corresponding dependencies.  I want to be able to read and print the timezone per row (commented out)</p>
  
  <p><strong>main.rs</strong></p>
  
  <pre><code>use postgres::{Client, Error, NoTls};
  extern crate chrono;
  use chrono::{DateTime, Local, NaiveDateTime, TimeZone, Utc};
  extern crate time;
  use time::Timespec;
  
  pub fn main() -&gt; Result&lt;(), Error&gt; {
      let mut client = Client::connect("host=localhost user=postgres", NoTls)?;
  
      client.simple_query(
          "
          CREATE TABLE mytable (
              name        text NOT NULL,
              timestamp   timestamptz NOT NULL)",
      )?;
  
      client.execute("INSERT INTO mytable VALUES ('bob', now());", &amp;[])?;
  
      for row in client.query("SELECT * FROM mytable", &amp;[])? {
          let name: &amp;str = row.get(0);
          // let timestamp: chrono::DateTime&lt;Utc&gt; = row.get(1);   //doesnt work
          // let timestamp: Timespec = row.get(1);  //doesnt work
          println!("name: {}", name);
          // println!("timestamp: {}", timestamp);
      }
  
      Ok(())
  }
  </code></pre>
  
  <p>Uncommenting</p>
  
  <pre><code>let timestamp: Timespec = row.get(1);  //doesnt work
  </code></pre>
  
  <pre class="lang-none prettyprint-override"><code>error[E0277]: the trait bound `time::Timespec: postgres_types::FromSql&lt;'_&gt;` is not satisfied  
  --&gt; src/main.rs:30:39  | 30 | 
  let timestamp: Timespec = row.get(1);   //doesnt work     
                                ^^^ the trait `postgres_types::FromSql&lt;'_&gt;` is not implemented for `time::Timespec`
  </code></pre>
  
  <p>Uncommenting</p>
  
  <pre><code>let timestamp: chrono::DateTime&lt;Utc&gt; = row.get(1);   //doesnt work
  </code></pre>
  
  <pre class="lang-none prettyprint-override"><code>error[E0277]: the trait bound `chrono::DateTime&lt;chrono::Utc&gt;: postgres_types::FromSql&lt;'_&gt;` is not satisfied
  --&gt; src/main.rs:29:52 29 |         
  let timestamp: chrono::DateTime&lt;Utc&gt; = row.get(1);   //doesnt work
                                             ^^^ the trait `postgres_types::FromSql&lt;'_&gt;` is not implemented for `chrono::DateTime&lt;chrono::Utc&gt;`
  </code></pre>
  
  <p><strong>Cargo.toml</strong></p>
  
  <pre><code>[dependencies]
  postgres = "0.17.0"
  chrono = "0.4.10"
  time = "0.1.14"
  </code></pre>
  
  <p>This link says to use <code>time = "0.1.14"</code>. latest version also fails  <a href="https://crates.io/crates/postgres/0.17.0-alpha.1" rel="nofollow noreferrer">https://crates.io/crates/postgres/0.17.0-alpha.1</a></p>