Re: COPY vs. INSERT

Поиск
Список
Период
Сортировка
От darcy@druid.net (D'Arcy J.M. Cain)
Тема Re: COPY vs. INSERT
Дата
Msg-id 20010622021444.4584A1A78@druid.net
обсуждение исходный текст
Ответ на Re: COPY vs. INSERT  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
Thus spake Tom Lane
> darcy@druid.net (D'Arcy J.M. Cain) writes:
> >> Obviously it isn't.  Care to show us the code?
> 
> > Sure.  ftp://ftp.vex.net/pub/glaccount.
> 
> PG_FUNCTION_INFO_V1(glaccount_cmp);
> Datum
> glaccount_cmp(PG_FUNCTION_ARGS)
> {
>         glaccount  *a1 = (glaccount *) PG_GETARG_POINTER(0);
>         glaccount  *a2 = (glaccount *) PG_GETARG_POINTER(1);
> 
>         PG_RETURN_BOOL(do_cmp(a1, a2));
> }
> 
> 
> The btree comparison function needs to return 1/0/-1, not boolean.
> Try PG_RETURN_INT32().

Doh!  I converted all the ints to booleans and got carried away.  Now
I just have to figure out why this worked on another system.

>         PG_RETURN_BOOL (!!do_cmp(a1, a2));
> 
> While these two are not actually wrong, that sort of coding always
> makes me itch.  Seems like
> 
>     PG_RETURN_BOOL (do_cmp(a1, a2) == 0);
> 
>     PG_RETURN_BOOL (do_cmp(a1, a2) != 0);
> 
> respectively would be cleaner, more readable, and more like the other
> comparison functions.  I've always thought that C's lack of distinction
> between booleans and integers was a bad design decision; indeed, your
> cmp bug kinda proves the point, no?

I agree with you about the lack of a true boolean type and it certainly
was the root of my error but I don't think that the other follows.  I
don't think that using the paradigms is wrong.  Kernighan gives a nice
talk on that subject.  He argues that you don't have to write for people
that don't know the language.  Rather you should strive for clarity but
use what programmers (in the same language) are used to.  For example;
   for (i = 1; i <= count; i++)

is correct but the equivalent (assuming i is a counter and is not used
in the loop itself)
   for (i = 0; i < count; i++)

is the right way to code not because it is more correct but because it
is what a future maintainer who is comfortable with C would understand
faster.

In this case there might be an argument for one or the other as I have
seen both styles used about equally.

OK, I guess I can work on the docs for the indexing too as there are some
differences with the new methods.

-- 
D'Arcy J.M. Cain <darcy@{druid|vex}.net>   |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.


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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Re: Good name for new lock type for VACUUM?
Следующее
От: Tatsuo Ishii
Дата:
Сообщение: Re: stuck spin lock with many concurrent users