Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitda1534d

Browse files
committed
Re-add type conversion examples.
1 parent2e6f975 commitda1534d

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

‎doc/src/sgml/typeconv.sgml

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/typeconv.sgml,v 1.28 2003/03/19 21:20:52 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/typeconv.sgml,v 1.29 2003/03/20 16:17:32 momjian Exp $
33
-->
44

55
<chapter Id="typeconv">
@@ -403,6 +403,57 @@ type to resolve the unknown literals to.
403403
</para>
404404
</example>
405405

406+
<example>
407+
<title>Absolute-Value and Factorial Operator Type Resolution</title>
408+
409+
<para>
410+
The <productname>PostgreSQL</productname> operator catalog has several
411+
entries for the prefix operator <literal>@</>, all of which implement
412+
absolute-value operations for various numeric data types. One of these
413+
entries is for type <type>float8</type>, which is the preferred type in
414+
the numeric category. Therefore, <productname>PostgreSQL</productname>
415+
will use that entry when faced with a non-numeric input:
416+
<screen>
417+
SELECT @ '-4.5' AS "abs";
418+
abs
419+
-----
420+
4.5
421+
(1 row)
422+
</screen>
423+
Here the system has performed an implicit conversion from <type>text</type> to <type>float8</type>
424+
before applying the chosen operator. We can verify that <type>float8</type> and
425+
not some other type was used:
426+
<screen>
427+
SELECT @ '-4.5e500' AS "abs";
428+
429+
ERROR: Input '-4.5e500' is out of range for float8
430+
</screen>
431+
</para>
432+
433+
<para>
434+
On the other hand, the postfix operator <literal>!</> (factorial)
435+
is defined only for integer data types, not for <type>float8</type>. So, if we
436+
try a similar case with <literal>!</>, we get:
437+
<screen>
438+
SELECT '20' ! AS "factorial";
439+
440+
ERROR: Unable to identify a postfix operator '!' for type 'text'
441+
You may need to add parentheses or an explicit cast
442+
</screen>
443+
This happens because the system can't decide which of the several
444+
possible <literal>!</> operators should be preferred. We can help
445+
it out with an explicit cast:
446+
<screen>
447+
SELECT CAST('20' AS int8) ! AS "factorial";
448+
449+
factorial
450+
---------------------
451+
2432902008176640000
452+
(1 row)
453+
</screen>
454+
</para>
455+
</example>
456+
406457
</sect1>
407458

408459
<sect1 id="typeconv-func">

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp