CONNECT Table Types - XCOL Table Type

You are viewing an old version of this article. View the current version here.

XCOL tables are based on another table or view, like PROXY tables. This type can be used when the object table has a column that contains a list of values.

Suppose we have a 'children' table that can be displayed as:

namechildlist
SophieManon, Alice, Antoine
ValentineArthur, Sidonie, Prune
BettyLucie, Louise
Corinne
ClaudeMarc

We can have a different view on these data, where each child will be associated with his/her mother by creating an XCOL table by:

CREATE TABLE xchild (
  mother char(12) NOT NULL flag=1,
  child varchar(30) DEFAULT NULL flag=2
  ) ENGINE=CONNECT table_type=XCOL tabname='children'
option_list='colname=child';

The COLNAME option specifies the name of the column receiving the list items. This will return from:

select * from xchild;

The requested view:

motherchild
SophieManon
SophieAlice
SophieAntoine
ValentineArthur
ValentineSidonie
ValentinePrune
BettyLucie
BettyLouise
BettyCharlie
CorinneNULL
ClaudeMarc

Several things should be noted here:

  • When the original childlist field is void, what happens depends on the NULL specification of the "multiple" column. If it is nullable, like here, a void string will generate a NULL value. However, if the column is not nullable, no row will be generated at all.
  • Blanks after the separator are ignored.
  • No copy of the original data was done. Both tables use the same source data.
  • Specifying the column definitions in the CREATE TABLE statement is optional.

The "multiple" column child can be used as any other column. For instance:

select * from xchild where substr(child,1,1) = 'A';

This will return:

MotherChild
SophieAlice
SophieAntoine
ValentineArthur

If a query does not involve the "multiple" column, no row multiplication will be done. For instance:

select mother from xchild;
mother
Sophie
Valentine
Betty
Corinne
Claude

The same occurs with other types of select statements, for instance:

select count(*) from xchild;      -- returns 11
select count(child) from xchild;  -- returns 10
select count(mother) from xchild; -- returns 5

Grouping also gives different result:

select mother, count(*) from xchild group by mother;

Replies:

mothercount(*)
Betty1
Claude1
Corinne1
Sophie1
Valentine1

While the query:

select mother, count(child) from xchild group by mother;

Gives the more interesting result:

mothercount(child)
Betty3
Claude1
Corinne0
Sophie3
Valentine3

Some more options are available for this table type:

OptionDescription
Sep_charThe separator character used in the "multiple" column, defaults to the comma.
MultIndicates the max number of multiple items. It is used to internally calculate the max size of the table and defaults to 10. (To be specified in OPTION_LIST).

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.