Re: Fix PL/Python metadata when there is no result

Поиск
Список
Период
Сортировка
От Peter Eisentraut
Тема Re: Fix PL/Python metadata when there is no result
Дата
Msg-id 1332614886.15083.8.camel@vanquo.pezone.net
обсуждение исходный текст
Ответ на Re: Fix PL/Python metadata when there is no result  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: Fix PL/Python metadata when there is no result
Список pgsql-hackers
On ons, 2012-03-07 at 17:14 -0500, Tom Lane wrote:
> Peter Eisentraut <peter_e@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"?




В списке pgsql-hackers по дате отправления:

Предыдущее
От: Michael Tautschnig
Дата:
Сообщение: Re: Weak-memory specific problem in ResetLatch/WaitLatch (follow-up analysis)
Следующее
От: Joshua Berkus
Дата:
Сообщение: Re: Gsoc2012 Idea --- Social Network database schema