Tom Lane wrote:
Thomas Hallgren <[EMAIL PROTECTED]> 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


---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Reply via email to