From: | darcy(at)druid(dot)net (D'Arcy J(dot)M(dot) Cain) |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: COPY vs. INSERT |
Date: | 2001-06-22 02:14:44 |
Message-ID: | 20010622021444.4584A1A78@druid.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Thus spake Tom Lane
> darcy(at)druid(dot)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(at){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.
From | Date | Subject | |
---|---|---|---|
Next Message | Tatsuo Ishii | 2001-06-22 02:31:05 | Re: stuck spin lock with many concurrent users |
Previous Message | Tom Lane | 2001-06-22 00:10:14 | Re: Re: Good name for new lock type for VACUUM? |