Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm running Apache 2.2, PHP 5.2, and Postgres 8.2 on Windows, and I'm seeing something funky in Apache's error.log file. Occasionally, I'll see the message "row number -1 is out of range 0..-1" pop up over and over. Unlike all the other lines in that log file, there's no timestamp or log level. Just that exact string.

Googling around, it appears that message is, character for character, a common Postgres error message, but is not an Apache error. I've seen it happen multiple times, and on several different servers. I can't seem to reproduce it, though. I've tried throwing all sorts of error ridden database queries and result set inquiries at Postgres via PHP, and none of them seem to trigger that line being written to the log file. Is it possible for Postgres errors to be ending up in my Apache log file, and if so, how? What would trigger an error message like that?


share|improve this question

migrated from May 28 '10 at 18:07

This question came from our site for computer enthusiasts and power users.

up vote 4 down vote accepted

The error is thrown by PostgreSQL, but it's a message for the client. In this case your PHP-script. This script tries to get some information that's not there.

From the mailing list:

The above error happens if a program calls PQgetvalue(), PQgetlength(), or PQgetisnull() with a row number of -1 and if there were no rows in the result.

Does your script always check the resultset before doing something with the resultset?

share|improve this answer
I don't ever call any of those functions directly. I use the functions built in to PHP (pg_connect, pg_fetch_assoc, etc.) Do you know if PHP is calling those under the hood? I'm pretty good about checking to make sure I have a valid result set before trying to use it, but even if I comment out that check and intentionally try to use an invalid result set, PHP simply returns false and prints an error to standard out about the first parameter not being a valid resource. I still don't get any Postgres errors in my Apache log. I'm on 5.2.6. Could it be a bug in that version of PHP? – Warren Pena Jun 3 '10 at 20:56
I found it. It turns out a PHP extension I'm using does call those functions directly, and sure enough, it wasn't bothering to check for a valid result set before using it. Thanks for the help! – Warren Pena Jun 3 '10 at 22:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.