--- apr_dbd_pgsql.c.old 2008-05-30 22:45:51.000000000 +0200 +++ apr_dbd_pgsql.c 2008-10-15 12:38:30.000000000 +0200 @@ -218,7 +218,12 @@ static const char *dbd_pgsql_get_name(const apr_dbd_results_t *res, int n) { - return (res->res ? PQfname(res->res, n) : NULL); + if (res->res) { + if ((n>=0) && (PQnfields(res->res) > n)) { + return PQfname(res->res,n); + } + } + return NULL; } static int dbd_pgsql_get_row(apr_pool_t *pool, apr_dbd_results_t *res,