From: | will trillich <will(at)serensoft(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | composite data types |
Date: | 2001-03-29 00:35:42 |
Message-ID: | 20010328183542.B16649@mail.serensoft.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
someone just point me to the 'composite data types'
documentation, please... (note that this is NOT inheritance):
-- first we roll-our-own datatypes:
CREATE TABLE vol (
high int4,
wide int4,
deep int4
);
CREATE TABLE changes (
who int4,
at datetime
);
--now we incorporate those composite types in a new table
CREATE TABLE something (
info varchar(30),
munged changes, -- use the composite CHANGES type
dimensions vol, -- use composite VOLume type
other char(2)
);
\d something
Table "something"
Attribute | Type | Modifier
------------+-------------+----------
info | varchar(30) |
munged | changes |
dimensions | vol |
other | char(2) |
--here we try to utilize those composite gizmos-go-boom:
INSERT INTO something VALUES(
'whatever',100,now(),36,24,36,'zx'
);
ERROR: Attribute 'munged' is of type 'changes' but expression is of type 'int4'
You will need to rewrite or cast the expression
INSERT INTO something VALUES(
'whatever',(100,now()),(36,24,36),'zx'
);
ERROR: parser: parse error at or near ","
INSERT INTO something (info,other) VALUES( 'whatever','zx');
INSERT 937857 1
-- this works, because we avoid the composite fields altogether.
INSERT INTO something.dimensions VALUES (36,24,36);
ERROR: parser: parse error at or near "."
INSERT INTO something(dimensions) VALUES (36,24,36);
ERROR: Attribute 'dimensions' is of type 'vol' but expression is of type 'int4'
You will need to rewrite or cast the expression
update something set dimensions = (36,24,36);
ERROR: parser: parse error at or near ";"
update something set dimensions = (36,24,36)::vol;
ERROR: parser: parse error at or near "::"
select * from something;
info | munged | dimensions | other
----------+--------+------------+-------
whatever | | | zx
(1 row)
so, HOW can you use a composite type? where's the doc?
--
It is always hazardous to ask "Why?" in science, but it is often
interesting to do so just the same.
-- Isaac Asimov, 'The Genetic Code'
will(at)serensoft(dot)com
http://newbieDoc.sourceforge.net/ -- we need your brain!
http://www.dontUthink.com/ -- your brain needs us!
From | Date | Subject | |
---|---|---|---|
Next Message | Joseph Shraibman | 2001-03-29 00:40:21 | Re: explain shows lots-o-preliminary sorting |
Previous Message | Soma Interesting | 2001-03-29 00:13:19 | stored procedure and timestamp |