Re: User Defined Types in Java

From: Thomas Hallgren <thomas(at)tada(dot)se>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Martijn van Oosterhout <kleptog(at)svana(dot)org>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: User Defined Types in Java
Date: 2006-02-13 19:13:17
Message-ID: 43F0DA4D.3000702@tada.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane wrote:
> Thomas Hallgren <thomas(at)tada(dot)se> writes:
>
>> What I'm proposing should be an addition that also can be seen as the
>> beginning of a path to migrate the CREATE TYPE construct to conform with
>> the SQL 2003 standard.
>>
>
> I'd be interested to see where in the SQL2003 spec the syntax you are
> proposing can be found.
>
The PostgreSQL specific semantics with input/output/receive/send is are
not in the SQL 2003 standard. But it does define how methods can be
declared on a type and to me, the input/output/receive/send are as close
to constructors and instance methods as you can get. I'm *not*
suggesting a full implementation of this. I am merely stating that
moving functions into the type and adding a column to the pg_proc table
that allows a function to be tied to a type is a step in that direction:

Here's an example using SQL 2003 syntax (from JRT-2003). The BNF is below:

CREATE TYPE addr EXTERNAL NAME 'address_classes_jar:Address'
LANGUAGE JAVA
AS (
street_attr CHARACTER VARYING(50) EXTERNAL NAME 'street',
zip_attr CHARACTER(10) EXTERNAL NAME 'zip'
)
CONSTRUCTOR METHOD addr ()
RETURNS addr SELF AS RESULT
EXTERNAL NAME 'Address',
CONSTRUCTOR METHOD addr (s_parm CHARACTER VARYING(50), z_parm
CHARACTER(10))
RETURNS addr SELF AS RESULT
EXTERNAL NAME 'Address',
METHOD to_string ()
RETURNS CHARACTER VARYING(255)
EXTERNAL NAME 'toString',
STATIC METHOD contiguous (A1 addr, A2 addr)
RETURNS CHARACTER(3)
EXTERNAL NAME 'contiguous';

<user-defined type definition> ::= CREATE TYPE <user-defined type body>
<user-defined type body> ::=
<schema-resolved user-defined type name>
[ <subtype clause> ]
[ AS <representation> ]
[ <user-defined type option list> ]
[ <method specification list> ]

...

<method specification list> ::=
<method specification> [ { <comma> <method specification> }... ]

<method specification> ::=
<original method specification>
| <overriding method specification>

<original method specification> ::=
<partial method specification> [ SELF AS RESULT ] [ SELF AS LOCATOR ]
[ <method characteristics> ]

<overriding method specification> ::= OVERRIDING <partial method
specification>

<partial method specification> ::=
[ INSTANCE | STATIC | CONSTRUCTOR ]
METHOD <method name> <SQL parameter declaration list>
<returns clause>
[ SPECIFIC <specific method name> ]
<specific method name> ::= [ <schema name> <period> ]<qualified identifier>

<method characteristics> ::= <method characteristic>...

<method characteristic> ::=
<language clause>
| <parameter style clause>
| <deterministic characteristic>
| <SQL-data access indication>
| <null-call clause>

Regards,
Thomas Hallgren

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2006-02-13 19:14:33 Re: Using stats_command_string for xact statistics
Previous Message Andrew Dunstan 2006-02-13 19:05:17 Re: psql & readline & win32