[Pljava-dev] testing for equality in user-defined types in select statements

From: bgiles at coyotesong(dot)com (Bear Giles)
To:
Subject: [Pljava-dev] testing for equality in user-defined types in select statements
Date: 2011-12-27 17:41:56
Message-ID: CALBNtw6Ko7Grv9sbwNN9ndNidUL5Wct9yF6coCknvhR6ScPjOw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pljava-dev

Thanks.

Three more questions....

1) what are the two methods that are required for hash joins. I'm sure
they're related to the hashCode method but I haven't come across how to
make the link. I might have overlooked it though - I've been reading a lot
of documentation but Google often returns really old documentation and I
don't always catch that. :-(

2) I'm having problems defining one of my operations. The UDT is
"Rational", for rational numbers. I don't have a problem defining the
ordering operations between two rational values but I'm also trying to
define ordering operations between a Rational and a float8.

I've defined my method

java:
public static boolean lessThan(Rational p, double q);

postgresql.ddr:
CREATE FUNCTION javatest.rational_lt(javatest.rational, float8)
RETURNS bool
AS 'sandbox.Rational.lessThan'
LANGUAGE JAVA IMMUTABLE STRICT;

CREATE OPERATOR < (
leftarg = javatest.rational, rightarg = float8, procedure =
javatest.rational_lt,
commutator = > , negator = >=
);

but when I try to load the jar file I get

ERROR: function javatest.rational_lt(javatest.rational, double
precision) does not exist
CONTEXT: SQL statement "CREATE OPERATOR < ( leftarg =
javatest.rational, rightarg = float8, procedure = javatest.rational_lt,
commutator = > , negator = >= )"

Ideas?

3) What about aggregate functions? Sum(), min(), etc. Are they just
functions that take a SETOF (sql) and array (java)?

I know that casts are created with 'CREATE CAST' but haven't tried adding a
cast from double to rational yet.

BTW I'm putting up an introduction on my blog,
http://invariantproperties.com/. I'm currently working on part 4, types,
and trying to hit everything that I would want from the java side to make
it look like a first-class object instead of just a way to store data -
integration with hibernate, the operations and indexes, etc.

On Mon, Dec 26, 2011 at 9:02 PM, Kris Jurka <jurka at ejurka.com> wrote:

> On 12/26/2011 7:41 PM, Bear Giles wrote:
>
>> I have a UDT for rational numbers. I want to be able to add it in
>> select statements but it doesn't work.
>> >
>> select f.value, f.foo, b.bar from foo f join bar b on (f.value =
>> b.value);
>>
>> I vaguely recall that there were standard function names for this when I
>> played with C UDT years ago but that was PSQL version 5.x or 6.x. Is
>> that still the case? In either case the wiki should be updated.
>>
>>
> You are looking for CREATE OPERATOR for equality/comparison and CREATE
> OPERATOR CLASS for ordering definition. These are no different for pljava
> types vs any other implemented type.
>
> Kris Jurka
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pgfoundry.org/pipermail/pljava-dev/attachments/20111227/6bf576f6/attachment.html>

In response to

Responses

Browse pljava-dev by date

  From Date Subject
Next Message Kris Jurka 2011-12-27 18:10:02 [Pljava-dev] testing for equality in user-defined types in select statements
Previous Message Kris Jurka 2011-12-27 04:02:48 [Pljava-dev] testing for equality in user-defined types in select statements