public function lastInsertId($name = null)
    {
        // checking for nulls, Postgres doesn't handle nulls at all here
        if(is_null($name)) {
            throw new \Exception('Postgres requires a sequence name to get the last insert ID');
        }

        // use the primary key to try to get the sequence name
        $primary_key = $this->getPrimaryKey($name);
        $id = $this->pdo->lastInsertId($name.'_'.$primary_key.'_seq');
        if($id === false || is_null($id)) {
            throw new \Exception("Can't get last insert ID for ".$name."; you must supply the correct sequence name.");
        }
        return $id;
    }