1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
8
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
10
HREF="mailto:pgsql-docs@postgresql.org"><LINK
12
TITLE="PostgreSQL 9.1beta1 Documentation"
13
HREF="index.html"><LINK
15
TITLE="Type Conversion"
16
HREF="typeconv.html"><LINK
18
TITLE="Type Conversion"
19
HREF="typeconv.html"><LINK
22
HREF="typeconv-oper.html"><LINK
25
HREF="stylesheet.css"><META
26
HTTP-EQUIV="Content-Type"
27
CONTENT="text/html; charset=ISO-8859-1"><META
29
CONTENT="2011-04-27T21:20:33"></HEAD
35
SUMMARY="Header navigation table"
47
>PostgreSQL 9.1beta1 Documentation</A
56
TITLE="Type Conversion"
66
TITLE="Type Conversion"
74
>Chapter 10. Type Conversion</TD
80
TITLE="Type Conversion"
90
HREF="typeconv-oper.html"
104
NAME="TYPECONV-OVERVIEW"
111
> is a strongly typed language. That is, every data item
112
has an associated data type which determines its behavior and allowed usage.
116
> has an extensible type system that is
117
more general and flexible than other <ACRONYM
121
Hence, most type conversion behavior in <SPAN
125
is governed by general rules rather than by <I
126
CLASS="FOREIGNPHRASE"
129
heuristics. This allows the use of mixed-type expressions even with
130
user-defined types.</P
135
> scanner/parser divides lexical
136
elements into five fundamental categories: integers, non-integer numbers,
137
strings, identifiers, and key words. Constants of most non-numeric types are
138
first classified as strings. The <ACRONYM
141
> language definition
142
allows specifying type names with strings, and this mechanism can be used in
146
> to start the parser down the correct
147
path. For example, the query:
151
>SELECT text 'Origin' AS "label", point '(0,0)' AS "value";
159
has two literal constants, of type <TT
166
If a type is not specified for a string literal, then the placeholder type
170
> is assigned initially, to be resolved in later
171
stages as described below.</P
173
>There are four fundamental <ACRONYM
176
> constructs requiring
177
distinct type conversion rules in the <SPAN
195
> type system is built around a
196
rich set of functions. Functions can have one or more arguments.
201
overloading, the function name alone does not uniquely identify the function
202
to be called; the parser must select the right function based on the data
203
types of the supplied arguments.</P
212
> allows expressions with
213
prefix and postfix unary (one-argument) operators,
214
as well as binary (two-argument) operators. Like functions, operators can
215
be overloaded, so the same problem of selecting the right operator
231
> statements place the results of
232
expressions into a table. The expressions in the statement must be matched up
233
with, and perhaps converted to, the types of the target columns.</P
242
>, and related constructs</DT
245
>Since all query results from a unionized <TT
249
must appear in a single set of columns, the types of the results of each
253
> clause must be matched up and converted to a uniform set.
254
Similarly, the result expressions of a <TT
258
converted to a common type so that the <TT
261
> expression as a whole
262
has a known output type. The same holds for <TT
278
>The system catalogs store information about which conversions, or
282
>, exist between which data types, and how to
283
perform those conversions. Additional casts can be added by the user
285
HREF="sql-createcast.html"
288
command. (This is usually
289
done in conjunction with defining new data types. The set of casts
290
between built-in types has been carefully crafted and is best not
293
>An additional heuristic provided by the parser allows improved determination
294
of the proper casting behavior among groups of types that have implicit casts.
295
Data types are divided into several basic <I
326
user-defined. (For a list see <A
327
HREF="catalog-pg-type.html#CATALOG-TYPCATEGORY-TABLE"
330
but note it is also possible to create custom type categories.) Within each
331
category there can be one or more <I
335
are preferred when there is a choice of possible types. With careful selection
336
of preferred types and available implicit casts, it is possible to ensure that
337
ambiguous expressions (those with multiple candidate parsing solutions) can be
338
resolved in a useful way.</P
340
>All type conversion rules are designed with several principles in mind:
347
>Implicit conversions should never have surprising or unpredictable outcomes.</P
351
>There should be no extra overhead in the parser or executor
352
if a query does not need implicit type conversion.
353
That is, if a query is well-formed and the types already match, then the query should execute
354
without spending extra time in the parser and without introducing unnecessary implicit conversion
355
calls in the query.</P
357
>Additionally, if a query usually requires an implicit conversion for a function, and
358
if then the user defines a new function with the correct argument types, the parser
359
should use this new function and no longer do implicit conversion to use the old function.</P
369
SUMMARY="Footer navigation table"
398
HREF="typeconv-oper.html"
b'\\ No newline at end of file'