Jay West wrote:
You wrote....
SELECT book, author FROM titles
WHERE isbn_publisher(book) > isbn_publisher('1-234-56789-X'::isbn);
Specifically:
- return the values of the "book" and "author" fields
- from the "titles" table
- for those records in which the "isbn_publisher()" [1] function
returns a value that exceeds that of the isbn_publisher()'s
value for the isbn data type [2] corresponding to the string
representation "1-234-56789-X"
[1] defined a returning the value of the Publisher Identifier
in the ISBN argument -- "234" in the second instance, here
[2] the "::isbn" is an explicit type cast in this case from
a string to an "isbn"
I think I'd need more explanation. I'm not sure exactly what you're
ISBN's have four parts: Group Identifier, Publisher ID, Title ID
and Check Digit. Check Digit is redundant -- if you have the
other three parts, you can derive (verify!) the Check DIgit.
Parts are separated by hyphens. Or spaces (but not a mixture thereof).
Always 9 digits [1] -- plus the check digit (which may be an 'X'
as it is computed modulo 11 -- X == 10).
But, the pisser is that the positions of the hyphens vary
as a function of the 9 digit "value" represented. I.e. for
a particular value, the hyphens (or spaces) *must* be in certain
positions (though the third one always precedes the check digit).
As expected, the first set of digits before the first hyphen
is the Group ID; the second set of digits is the Publisher ID;
and the third set is the Title ID.
Some examples:
0-10-337439-6
1-234-56788-1
1-234-56789-X
1 234 56790 3
1-55529-512-6
9953-26-719-1
Some *bad* values:
01-0-337439-6 (incorrect hyphenation)
1-234-5678-8-1 (wrong number of hyphens)
1-234-5678-3 (wrong number of digits)
1 234 56790-3 (can't mix spaces and hyphens)
1-55529-512-7 (check digit is incorrect)
9976-990-00-6 (this number just hasn't been allocated yet)
The point of all this is that ISBN's aren't "just numbers".
Though one could chose to *represent* them as numbers
(a long/int32 works well).
And, that ISBN's have information contained *within* them
(heh heh heh... don't you just LOVE all this SURPLUS
PUNCTUATION i stick in my comments?? :> ) like the
ID of the publisher, etc.
So, you want to be able to extract that information from
a particular (valid) ISBN:
isbn_group(isbn) returns the group ID of the isbn argument
isbn_publisher(isbn) returns the publisher ID of the argument
isbn_title(isbn) returns the title ID of the argument
isbn_check_digit(isbn) returns the check digit
Publisher ID's are only significant within a particular
Group ID. I.e. publisher 234 in group 1 is not the same entity
as publisher 234 in group 0. Likewise, title ID's are only
significant within a particular (group,publisher) pair.
Obviously, title 56789 for (group,publisher) of (1,234) is
not the same as for (0,234) or (1,235)! [clearly different
ISBN's so different "books"]
Given that, you might want to do a query to identify all
other titles by the same publisher as some particular book
that you happen to have:
SELECT book, name_of_book FROM titles
WHERE isbn_group(book) = isbn_group('1-234-56789-X'::isbn)
& isbn_publisher(book) = isbn_publisher('1-234-56789-X'::isbn)
;
I.e. find books whose's publisher identifier agrees with the
publisher ID in '1-234-56789-X' (that is, '234') and whose
group ID also agrees (that is, '1') -- since a publisher
is only known to be "the same" if he is in the same group.
This has drifted further off topic :-( But, it was intended
to show how cluttered with punctuation this query became
for something "easy".
Consider how I might ask "What is the title of the book
having the ISBN immediately *after* this one?":
SELECT book, name_of_book FROM titles
WHERE book = isbn_build(
isbn_group('1-234-56789-X'::isbn)
, isbn_publisher('1-234-56789-X'::isbn)
, isbn_title('1-234-56789-X'::isbn) + 1
);
[2]
given:
isbn isbn_build(int groupID, int pubID, int titleID)
So, how would you extract this information from the "book"
datum in pick? Presumably, with some sort of user defined
operator? Or, would you have to split the ISBN into 3
different fields (group, publisher, title) and store it
that way so you could manipulate each independantly?
[remember, what we're discussing is the role of PUNCTUATION!]
expressing. Example data would help? Also, Pick
generally didn't really
have a concept of datatyping.
Ah, OK.
Everything was always stored as strings.
Like REXX, etc.?
Anything that needed to be treated as numeric was
converted on the fly
during runtime as indicated by context.
That seems to suggest that you would have to split the ISBN
into its component parts in order to be able to manipulate
those parts. I.e. you couldn't just "add one" to
"1-234-56789-X"?
I really find it hard to figure out how to do away with
parens/braces/etc. They just have too big a role in
The Way We Do Things. :-( But, for those "non symbol
manipulators", they really are not very intuitive!
[1] ISBN is now being augmented by ISBN-13
[2] Technically, I would have to make sure isbn_title()+1 did
not exceed the maximum title ID for that (group,publisher) -- which
varies with the (group,publisher)!