hawq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dyozie <...@git.apache.org>
Subject [GitHub] incubator-hawq-docs pull request #85: Feature/hawq-1251
Date Wed, 11 Jan 2017 23:07:29 GMT
Github user dyozie commented on a diff in the pull request:

    https://github.com/apache/incubator-hawq-docs/pull/85#discussion_r95693447
  
    --- Diff: markdown/reference/sql/CREATE-CAST.html.md.erb ---
    @@ -0,0 +1,101 @@
    +---
    +title: CREATE CAST
    +---
    +
    +Defines a new cast.
    +
    +## <a id="topic1__section2"></a>Synopsis
    +
    +``` pre
    +CREATE CAST (sourcetype AS targettype) 
    +       WITH FUNCTION funcname (argtypes) 
    +       [AS ASSIGNMENT | AS IMPLICIT]
    +
    +CREATE CAST (sourcetype AS targettype) WITHOUT FUNCTION 
    +       [AS ASSIGNMENT | AS IMPLICIT]
    +```
    +
    +## <a id="topic1__section3"></a>Description
    +
    +`CREATE CAST` defines a new cast. A cast specifies how to perform a conversion between
two data types. For example,
    +
    +```pre
    +SELECT CAST(42 AS text);
    +```
    +
    +converts the integer constant 42 to type `text` by invoking a previously specified function,
in this `case text(int4)`. If no suitable cast has been defined, the conversion fails.
    +
    +Two types may be binary compatible, which means that they can be converted into one another
without invoking any function. This requires that corresponding values use the same internal
representation. For instance, the types `text` and `varchar` are binary compatible.
    +
    +By default, a cast can be invoked only by an explicit cast request, that is an explicit
`CAST(x AS typename)` or `x:: typename` construct.
    +
    +If the cast is marked `AS ASSIGNMENT` then it can be invoked implicitly when assigning
a value to a column of the target data type. For example, supposing that `foo.f1` is a column
of type text, then:
    +
    +``` pre
    +INSERT INTO foo (f1) VALUES (42);
    +```
    +will be allowed if the cast from type integer to type text is marked `AS ASSIGNMENT`,
otherwise not. The term assignment cast is typically used to describe this kind of cast.
    +
    +If the cast is marked `AS IMPLICIT` then it can be invoked implicitly in any context,
whether assignment or internally in an expression. The term *implicit cast* is typically used
to describe this kind of cast. For example, since `||` takes text operands,
    +
    +``` pre
    +SELECT 'The time is ' || now();
    +```
    +It is wise to be conservative about marking casts as implicit. An overabundance of implicit
casting paths can cause HAWQ to choose surprising interpretations of commands, or to be unable
to resolve commands at all because there are multiple possible interpretations. A good rule
of thumb is to make a cast implicitly invokable only for information-preserving transformations
between types in the same general type category. For example, the cast from int2 to int4 can
reasonably be implicit, but the cast from float8 to int4 should probably be assignment-only.
Cross-type-category casts, such as text to int4, are best made explicit-only.
    --- End diff --
    
    Need to make all data types `code format` in this paragraph.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message