OpenSource For You

User-defined type systems

-

PostgreSQL allows users to define their own data-types, which can be used in the same way as the in-built datatypes. A user-defined data-type can be a base type, a composite WySH, D GRPDLQ Rr DQ HQXPHrDWLR­Q. UVHr-GHILQHG types can be defined by using the CREATE TYPE ( base, composite and enumeratio­n) or CREATE DOMAIN (domain) commands.

Composite types are a collection of other data-types with DVVRFLDWHG fiHOG QDPHV, OLNH VWrXFWXrHV LQ C. ThH PHPEHrV RI a composite type can be accessed in SQL queries, functions, HWF. $Q HxDPSOH GHfiQLQJ D FRPSRVLWH WySH ‘complex’ can be found in this article.

Domain types, on the other hand, can be created by constraini­ng the base types. Although the constraint­s restrict the valid values of a domain type to a subset of values allowed by the underlying base type, for many purposes, a base type and the types based on it are interchang­eable.

Base types are usually implemente­d in a low-level language like C, which is below the level of the SQL language. The behaviour of such a data-type needs to be GHfiQHG Ey WhH XVHr LQ WHrPV RI LQSXW/RXWSXW IXQFWLRQV (XVXDOOy inverses of each other), which decide how the data-type appears in string form for input/output by the user. The same functions will decide how the type is organised in memory. The implementa­tion can be provided through shared libraries.

Newspapers in English

Newspapers from India