Greenplum 自定义复合类型 数组

简介:

标签

PostgreSQL , Greenplum , composite type array


背景

如果你现在要在Greenplum中创建一个复合类型,是不会自动给你创建对应的数组类型的。(而实际上PostgreSQL 在2007年已经支持了这个功能)

Greenplum需要等到5.0,才能使用上它了。

https://github.com/greenplum-db/gpdb/commit/8954a537ee6199a80c38581fd3cd7ed463abbdea

Support arrays of composite types  
Backport from upstream with this commit:  
  
    commit bc8036f  
    Author: Tom Lane <tgl@sss.pgh.pa.us>  
    Date:   Fri May 11 17:57:14 2007 +0000  
  
        Support arrays of composite types, including the rowtypes of regular tables  
        and views (but not system catalogs, nor sequences or toast tables).  Get rid  
        of the hardwired convention that a type's array type is named exactly "_type",  
        instead using a new column pg_type.typarray to provide the linkage.  (It still  
        will be named "_type", though, except in odd corner cases such as  
        maximum-length type names.)  
  
        Along the way, make tracking of owner and schema dependencies for types more  
        uniform: a type directly created by the user has these dependencies, while a  
        table rowtype or auto-generated array type does not have them, but depends on  
        its parent object instead.  
  
        David Fetter, Andrew Dunstan, Tom Lane  
 master (#1)  5.0.0-alpha.1 5.0.0-alpha.0  
1 parent 5b33bee commit 8954a537ee6199a80c38581fd3cd7ed463abbdea @HaozhouWang HaozhouWang committed on 9 Mar 2016  

https://www.postgresql.org/docs/8.2/static/sql-createtype.html

Array Types

Whenever a user-defined base data type is created, PostgreSQL automatically creates an associated array type,   
whose name consists of the base type's name prepended with an underscore.   
The parser understands this naming convention, and translates requests for columns of type foo[] into requests for type _foo.   
The implicitly-created array type is variable length and uses the built-in input and output functions array_in and array_out.  
  
You might reasonably ask why there is an ELEMENT option, if the system makes the correct array type automatically.   
The only case where it's useful to use ELEMENT is when you are making a fixed-length type that happens to be internally an array of a number of identical things,  
and you want to allow these things to be accessed directly by subscripting, in addition to whatever operations you plan to provide for the type as a whole.   
For example, type name allows its constituent char elements to be accessed this way.   
A 2-D point type could allow its two component numbers to be accessed like point[0] and point[1].   
  
Note that this facility only works for fixed-length types whose internal form is exactly a sequence of identical fixed-length fields.   
A subscriptable variable-length type must have the generalized internal representation used by array_in and array_out. For historical reasons   
(i.e., this is clearly wrong but it's far too late to change it),   
subscripting of fixed-length array types starts from zero, rather than from one as for variable-length arrays.  
相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍如何基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
人工智能 缓存 前端开发
9374 44
人工智能 JavaScript 开发工具
3885 10
开发工具 Swift git
1502 2
缓存 JavaScript Shell
1780 3
人工智能 JavaScript 测试技术
1373 0
人工智能 Java BI
911 0
人工智能 JavaScript 测试技术
608 4
Shell API 调度
971 3