On ons, 2012-03-07 at 17:14 -0500, Tom Lane wrote: > Peter Eisentraut <pete...@gmx.net> writes: > > On ons, 2012-03-07 at 16:49 -0500, Tom Lane wrote: > >> Still, it seems rather arbitrary to say that the row count property is > >> the thing to test for that purpose and no other is. Why not return None > >> for any property that's not sensible? > > > Hmm, above you said you were in favor of throwing an error rather than > > returning None? > > I said it was a reasonable alternative, not that it was the only one > we should consider. The behavior of .nrows() might be accidental, > but perhaps it is a preferable model to adopt.
It turns out I was mistaken about the .nrows() behavior. It returns 0 even for utility commands, because the value comes straight from SPI_processed. But SPI_processed is a C variable, which can't have a "not applicable" value, so that doesn't necessarily mean other languages can't handle this differently. After pondering this for several days now I still think the best approach is to change .nrows() to return None for utility commands and have the other metadata functions throw exceptions. Then the programming style would be "if there are rows, give me metadata about them". The alternative would be to introduce another function "has_rows" or something, but then how would that be more intuitive than saying "nrows() is not None"? -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers