Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old November 23rd, 2005, 01:35 AM
Thomas Hallgren
Guest
 
Posts: n/a
Default User Defined Types and SQL2003

Below is an example of how a UDT can be created and used for a specific
language according to the SQL 2003 spec. The syntax is fetched from
"Routines and Types Using Java(SQL/JRT)". Aside from the "LANGUAGE JAVA"
this is not Java specific at all.

The PL/Java project would of course be interested in if Postgres could
support this syntax and willing to participate in an effort to implement
it too of course. What has been done already? What are the plans for SQL
2003 compliance with respect to UDT's?

Regards,

Thomas Hallgren



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 VARCHAR(50), z_parm CHAR(10))
RETURNS addr SELF AS RESULT
EXTERNAL NAME 'Address',
METHOD to_string ()
RETURNS CHARACTER VARYING(255)
EXTERNAL NAME 'toString',
METHOD remove_leading_blanks ()
RETURNS addr SELF AS RESULT
EXTERNAL NAME 'removeLeadingBlanks',
STATIC METHOD contiguous (A1 addr, A2 addr)
RETURNS CHARACTER(3)
EXTERNAL NAME 'contiguous';

Given a table created as:

CREATE TABLE emps (
name VARCHAR(30),
home_addr addr
)

it would then be possible to write:

INSERT INTO emps VALUES (
'Bob Smith',
NEW addr('432 Elm Street', '95123'))

and selects like:

SELECT home_addr.to_string() FROM emps WHERE name = 'Bob Smith';


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles