Composite Types
От | mjp@ornl.gov |
---|---|
Тема | Composite Types |
Дата | |
Msg-id | 20000606181113.A5915@grail.lsd.ornl.gov обсуждение исходный текст |
Ответы |
Re: Composite Types
|
Список | 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@ornl.gov
В списке pgsql-general по дате отправления: