Custom types and arrays

From: "mlunnon (at) RWA" <mlunnon(at)rwa-net(dot)co(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Subject: Custom types and arrays
Date: 2003-10-31 18:12:44
Message-ID: 3FA2A61C.3010207@rwa-net.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
Hi,<br>
<br>
Does anyone know how to declare arrays of custom types?&nbsp; The
documentation says:<br>
<br>
<blockquote>As discussed earlier, PostgreSQL fully supports arrays of
base types. Additionally, PostgreSQL supports arrays of user-defined
types as well. When you define a type, PostgreSQL automatically
provides support for arrays of that type. For historical reasons, the
array type has the same name as the user-defined type with the
underscore character _ prepended.<br>
</blockquote>
When I run the following code:<br>
<br>
CREATE TYPE TEST_TYPE AS (<br>
&nbsp;&nbsp;&nbsp; ID&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; INTEGER,<br>
&nbsp;&nbsp;&nbsp; CODE&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; VARCHAR(40)<br>
);<br>
<br>
CREATE OR REPLACE FUNCTION Test1( ) RETURNS TEST_TYPE[20] AS'<br>
DECLARE<br>
&nbsp;&nbsp;&nbsp; aoTesttype TEST_TYPE[20];<br>
BEGIN<br>
&nbsp;&nbsp;&nbsp; RETURN aoTestType;<br>
END;' LANGUAGE 'plpgsql';<br>
<br>
CREATE OR REPLACE FUNCTION Test2( ) RETURNS _TEST_TYPE AS'<br>
DECLARE<br>
&nbsp;&nbsp;&nbsp; aoTesttype _TEST_TYPE;<br>
BEGIN<br>
&nbsp;&nbsp;&nbsp; RETURN aoTestType;<br>
END;' LANGUAGE 'plpgsql';<br>
<br>
I get:<br>
psql:Supplements.sql:34: ERROR:&nbsp; Type "test_type[]" does not exist<br>
psql:Supplements.sql:41: ERROR:&nbsp; Type "_test_type" does not exist<br>
<br>
Can anyone help?<br>
<br>
Thanks in advance.<br>
<br>
Matthew<br>
</body>
</html>

Attachment Content-Type Size
unknown_filename text/html 1.7 KB

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Stephan Szabo 2003-10-31 19:16:33 Re: Attribute 'rtrim' is repeated
Previous Message Andrew Ayers 2003-10-31 16:25:34 Re: ALTER Table (another)