473,480 Members | 4,939 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Create a table with a structured UDT (user-defined type) as a column

Hi,

is it actually possible to create a table that has a UDT as a column
datatype?

e.g.:
CREATE TYPE addressType AS (
street INTEGER,
zip VARCHAR(30)) MODE DB2SQL

CREATE TABLE person (name VARCHAR(30), address addressType)

This doesn't seem to work. The statement SELECT * FROM person gives errors
(SQLSTATE=42741), and I haven't figured out how to store data in that table.
Apr 16 '06 #1
7 5262
Genus Neduba wrote:
Hi,

is it actually possible to create a table that has a UDT as a column
datatype?

e.g.:
CREATE TYPE addressType AS (
street INTEGER,
zip VARCHAR(30)) MODE DB2SQL

CREATE TABLE person (name VARCHAR(30), address addressType)

This doesn't seem to work. The statement SELECT * FROM person gives errors
(SQLSTATE=42741), and I haven't figured out how to store data in that table.

db2 => ? 42741;
SQLSTATE 42741: A transform group is not defined for a data type.

So.. have you read up on what a "transform group" is? ;-)

Here is a quick intro:
http://www-128.ibm.com/developerwork...dm-0506melnyk/

Cheers
Serge

PS: Who is running the IM department in Muenster? I know that Prof Heuer
is OO, but he's in Rostock.

PPS: Knut Stolze is The Man for structured types.. and in your timezone,
too.

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Apr 16 '06 #2
Okay, so I have to create a function that transforms the structured type.

But when I try to create that function and use the '||' operator I get the
error message SQLSTATE=42884
Apr 17 '06 #3
Genus Neduba wrote:
Okay, so I have to create a function that transforms the structured type.

But when I try to create that function and use the '||' operator I get the
error message SQLSTATE=42884

db2 => ? 42884;

SQLSTATE 42884: No routine was found with the specified name and compatible
arguments.
(Keep in mind that we may be geeks here, but at least I don't think in
SQLSTATE numbers ;-)

I'm taking a guess here that you tried to concatenate a number. DB2 is
using strong typing.
If you want to || a number you have to turn the number into a string first:
'HELLO' || CHAR(5)

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Apr 17 '06 #4
Okay, here the complete statement (but it's in german)

Your SQL-statement: CREATE FUNCTION loc_transform (location_t) RETURNS
VARCHAR(60) LANGUAGE SQL RETURN 'building ' || loc..building || ', floor '
|| loc..floor || ', room ' || loc..room || ', booth ' || loc..booth

Fehler: SQL-Abfrage nicht durchführbar. [IBM][CLI Driver][DB2/LINUX]
SQL0440N Es wurde keine berechtigte Routine "||" des Typs "FUNCTION" mit
kompatiblen Argumenten gefunden. LINE NUMBER=2. SQLSTATE=42884

and:
CREATE TYPE location_t AS (
building INTEGER,
floor INTEGER,
room INTEGER,
booth VARCHAR(30)) MODE DB2SQL
Apr 18 '06 #5
Genus Neduba wrote:
Okay, here the complete statement (but it's in german)

Your SQL-statement: CREATE FUNCTION loc_transform (location_t)
RETURNS
VARCHAR(60) LANGUAGE SQL RETURN 'building ' || loc..building || ', floor '
|| loc..floor || ', room ' || loc..room || ', booth ' || loc..booth

Fehler: SQL-Abfrage nicht durchführbar. [IBM][CLI Driver][DB2/LINUX]
SQL0440N Es wurde keine berechtigte Routine "||" des Typs "FUNCTION" mit
kompatiblen Argumenten gefunden. LINE NUMBER=2. SQLSTATE=42884

and:
CREATE TYPE location_t AS (
building INTEGER,
floor INTEGER,
room INTEGER,
booth VARCHAR(30)) MODE DB2SQL


Note that VARCHAR(60) is too short if the numbers are maxed out. You don't
want to run into a run-time problem then!!

CREATE FUNCTION loc_transform(loc location_t)
RETURNS VARCHAR(100)
LANGUAGE SQL
DETERMINISTIC
NO EXTERNAL ACTION
RETURN 'building ' || RTRIM(CHAR(loc..building)) ||
', floor ' || RTRIM(CHAR(loc..floor)) ||
', room ' || RTRIM(CHAR(loc..room)) ||
', booth ' || loc..booth

CREATE TRANSFORM FOR location_t my_transform (
FROM SQL WITH FUNCTION loc_transform )

CREATE TABLE t ( a int, b location_t )
INSERT INTO t VALUES (1, location_t()..building(1)..
floor(2)..room(3)..booth('booth'))
SET CURRENT DEFAULT TRANSFORM GROUP = my_transform

SELECT * FROM t

A B
----------- ---------------------------------------------------
1 building 1, floor 2, room 3, booth booth

1 record(s) selected.

Note that "TO SQL" transform functions/methods are a bit more complicated to
use. Have a look here for some examples:
http://publib.boulder.ibm.com/infoce...t/rsbp4165.htm

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Apr 18 '06 #6
Well, thanks, I guess this should work, but it doesn't. It's probably due to
the restrictions (restricted privileges for me) on our maschine.

But I got the idea. At least I can store and read from that table with
structured-UDTs as Columns (even if I can't display it).
Your SQL-statement: SELECT * FROM t

Fehler: SQL-Abfrage nicht durchführbar. [IBM][CLI Driver][DB2/LINUX]
SQL20015N Eine Umsetzungsgruppe "DB2_PROGRAM" ist für den Datentyp
"LOCATION_T" nicht definiert. SQLSTATE=42741
Apr 18 '06 #7
Genus Neduba wrote:
Well, thanks, I guess this should work, but it doesn't. It's probably due
to the restrictions (restricted privileges for me) on our maschine.

But I got the idea. At least I can store and read from that table with
structured-UDTs as Columns (even if I can't display it).
Your SQL-statement: SELECT * FROM t

Fehler: SQL-Abfrage nicht durchführbar. [IBM][CLI Driver][DB2/LINUX]
SQL20015N Eine Umsetzungsgruppe "DB2_PROGRAM" ist für den Datentyp
"LOCATION_T" nicht definiert. SQLSTATE=42741


If you have no current default transform group specified, DB2 falls back to
the "db2_program" transform group. The transform group that I created was
named "my_transform" and I used the explicit statement:

SET CURRENT DEFAULT TRANSFORM GROUP = my_transform

Note that the setting is only active in the current SQL session.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Apr 18 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
21321
by: Thomas Jerkins | last post by:
When I write a create table SQL statement I want to add some information about the column heading of each column. How does the exact syntax for the create table look like (which includes this column...
4
2292
by: Baoqiu Cui | last post by:
Hi, I was playing with MySQL (4.1.9) during the weekend, but noticed a minor problem and would like someone to explain this to me. Basically I could successfully create a table with one unique...
6
12252
by: Bruce | last post by:
I want to create a new table based on an existing table, but I don't want the tables to have any enforced relationship. Is this possible without having to do a CREATE TABLE and an INSERT? ...
3
7283
by: Carmine | last post by:
I have to add a date column to a db2/zos table with a blob column. Can I rename the blob table to old, create a new table with the date column, then insert/select the data from the old table? ...
0
1648
by: Hicham G. Elmongui | last post by:
is there a way to create a table with a certain type? CREATE TYPE typename AS (id integer, name varchar); and something like CREATE TABLE names OF TYPE typename. Is there a syntax to...
2
1834
by: miladhatam | last post by:
hi i know how can i create a table with sql command but i don't know how create a field with type integer ,autoNumber (auto increase) and Primary key Like id field in Access may you change...
33
2521
by: Stef Mientki | last post by:
hello, I discovered that boolean evaluation in Python is done "fast" (as soon as the condition is ok, the rest of the expression is ignored). Is this standard behavior or is there a compiler...
0
1886
by: jk9427 | last post by:
I'm creating an SQL table and it compiles fine, but in the spool file I have a level 30 error. Is this an actual problem, or can I procede? SQL0204 30 36 Position 3 ETBRAN in JKENDZIERS...
2
10480
by: zufie | last post by:
I am learning SQL using MS Access until I get SQL Server. I am trying to create a table that includes time and date columns. I receive the error: Syntax error in field definition. Here is my...
2
43920
by: jarea | last post by:
I have read quite a bit about this error but I have yet to find the solution to my problem. I am trying to execute the following mysql statement: alter table line_items add...
0
6905
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7080
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6736
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5331
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4772
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4478
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2994
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2980
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1299
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.