============================================================================
POSTGRESQL BUG REPORT TEMPLATE
============================================================================
Your name : Alan Curry
Your email address : [EMAIL PROTECTED]
System Configuration
---------------------
Architecture (example: Intel Pentium) :Pentium Pro
Operating System (example: Linux 2.0.26 ELF) :Linux 2.2.13 ELF
PostgreSQL version (example: PostgreSQL-6.5.2):PostgreSQL-6.5.3
Compiler used (example: gcc 2.8.0) :gcc 2.7.2.3
Please enter a FULL description of your problem:
------------------------------------------------
It is possible to select a phantom row from an empty table.
Please describe a way to repeat the problem. Please try to provide a
concise reproducible example, if at all possible:
----------------------------------------------------------------------
test=> create table foo(u text, i int);
CREATE
test=> select * from foo;
u|i
-+-
(0 rows)
test=> select u,min(i) from foo group by u;
u|min
-+---
|
(1 row)
#include <libpq-fe.h>
#include <stdio.h>
int main(void)
{
PGconn *db;
PGresult *res;
int r, c, i;
db=PQconnectdb("dbname=test");
if(PQstatus(db)!=CONNECTION_OK) {
fprintf(stderr, "PQconnectdb: %s", PQerrorMessage(db));
return 1;
}
res=PQexec(db, "drop table foo;");
if(PQresultStatus(res)!=PGRES_COMMAND_OK) {
fprintf(stderr, "died at %d %s", __LINE__, PQresultErrorMessage(res));
return 1;
}
res=PQexec(db, "create table foo(u text, i int);");
if(PQresultStatus(res)!=PGRES_COMMAND_OK) {
fprintf(stderr, "died at %d %s", __LINE__, PQresultErrorMessage(res));
return 1;
}
/* Hey Rocky, watch me pull a rabbit out of my hat! */
res=PQexec(db, "select u, min(i) from foo group by u;");
if(PQresultStatus(res)!=PGRES_TUPLES_OK) {
fprintf(stderr, "died at %d %s", __LINE__, PQresultErrorMessage(res));
return 1;
}
r=PQntuples(res);
if(!r)
return 0;
printf("Got %d row%s from a table with no rows in it!\n", r, r>1?"s":"");
c=PQnfields(res);
printf("Dumping row 0\n");
for(i=0;i<c;++i) {
printf("column %d (%s) is %snull, with value \"%s\"\n", i,
PQfname(res, i),
PQgetisnull(res, 0, i)?"":"not ",
PQgetvalue(res, 0, i));
}
return 0;
}
If you know how this problem might be fixed, list the solution below:
---------------------------------------------------------------------