Composite Types

From: mjp(at)ornl(dot)gov
To: pgsql-general(at)postgresql(dot)org
Cc: parangm(at)ornl(dot)gov
Subject: Composite Types
Date: 2000-06-06 22:11:13
Message-ID: 20000606181113.A5915@grail.lsd.ornl.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I appreciate any help I can get on this...Recently, I've been experimenting
with the user defined base-types (using CREATE TYPE) with successful results.
But, when it comes to handling classes as composite types, things are not
as straight forward. Here is a case. Suppose I define a composite type (table) called 'bulk':

Table "bulk"
Attribute | Type | Modifier
-----------+---------+----------
id | integer |
ofset | integer |
size | integer |

and use the composite type 'bulk' in another table called 'stuff' as in:

Table "stuff"
Attribute | Type | Modifier
-----------+---------+----------
id | integer |
name | text |
content | bulk |

My intent here is to maintain consistency between the instances of these
tables (i.e., for each instance of 'bulk', there would an equivalent instance
in the 'content' of 'stuff'.

My first question is what is the best way to insert into 'stuff'? I couldn't
come up with a simple solution other than creating the function new_bulk():

CREATE function new_bulk(int4, int4, int4) returns bulk as '
select $1, $2, $3
' LANGUAGE 'sql';

and using it to insert a row in 'stuff':

INSERT into stuff values (1,'test1',(new_bulk(7,8,9)));
INSERT into bulk values (7,8,9);

The 2nd question I have is how to come up with an output function (similar
to output_function in CREATE TYPE) to display 'content' of 'stuff' in
a suitable format? If I type:

select content from stuff;

I get:

content
-----------
136585664
(1 row)

and

select stuff.content.id from content;

gives me:

ERROR: init_fcache: Cache lookup failed for procedure 136585664

Any suggestions/help are appreciated.

Morey Parang
Oak Ridge National Laboratory
parangm(at)ornl(dot)gov

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2000-06-06 22:14:41 Re: Dump
Previous Message Merrill Oveson 2000-06-06 21:36:01 deferred primary key