File tree 2 files changed +33
-0
lines changed
2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -179,6 +179,7 @@ _393 TILs and counting..._
179
179
- [ Create A Composite Primary Key] ( postgres/create-a-composite-primary-key.md )
180
180
- [ Create hstore From Two Arrays] ( postgres/create-hstore-from-two-arrays.md )
181
181
- [ Creating Conditional Constraints] ( postgres/creating-conditional-constraints.md )
182
+ - [ Creating Custom Types] ( postgres/creating-custom-types.md )
182
183
- [ Day Of Week By Name For A Date] ( postgres/day-of-week-by-name-for-a-date.md )
183
184
- [ Day Of Week For A Date] ( postgres/day-of-week-for-a-date.md )
184
185
- [ Default Schema] ( postgres/default-schema.md )
Original file line number Diff line number Diff line change
1
+ # Creating Custom Types
2
+
3
+ PostgreSQL has support for creating custom types. When you need something
4
+ more expressive than the built-in types and you don't want your data spread
5
+ across multiple columns, you can instead create a custom type.
6
+
7
+ ``` sql
8
+ create type dimensions as (
9
+ width integer ,
10
+ height integer ,
11
+ depth integer
12
+ );
13
+ ```
14
+
15
+ This new type can then be used in the definition of a new table
16
+
17
+ ``` sql
18
+ create table moving_boxes (
19
+ id serial primary key ,
20
+ dims dimensions not null
21
+ );
22
+ ```
23
+
24
+ and when inserting data
25
+
26
+ ``` sql
27
+ insert into moving_boxes (dims) values (row(3 ,4 ,5 )::dimensions);
28
+ ```
29
+
30
+ See the [ ` create type `
31
+ docs] ( http://www.postgresql.org/docs/current/static/sql-createtype.html ) for
32
+ more details.
You can’t perform that action at this time.
0 commit comments