new typeconv example (was [HACKERS] More outdated documentation)
new typeconv example (was [HACKERS] More outdated documentation)
От:
Joe Conway <mail@joeconway.com>
Дата:
Index: doc/src/sgml/typeconv.sgml =================================================================== RCS file: /opt/src/cvs/pgsql-server/doc/src/sgml/typeconv.sgml,v retrieving revision 1.26 diff -c -r1.26 typeconv.sgml *** doc/src/sgml/typeconv.sgml 19 Feb 2003 04:06:28 -0000 1.26 --- doc/src/sgml/typeconv.sgml 8 Mar 2003 20:09:56 -0000 *************** *** 625,645 **** ! ! There are two substr functions declared in pg_proc. However, ! only one takes two arguments, of types text and int4. ! If called with a string constant of unspecified type, the type is matched up directly with the only candidate function type: ! tgl=> SELECT substr('1234', 3); ! substr ! -------- ! 34 (1 row) --- 625,645 ---- ! ! There are two rpad functions declared in pg_proc. However, ! only one takes three arguments, of types text, int4, and text. ! If called with the first string constant of unspecified type, the type is matched up directly with the only candidate function type: ! regression=# SELECT rpad('1234', 7, 'x'); ! rpad ! --------- ! 1234xxx (1 row) *************** *** 648,665 **** If the string is declared to be of type varchar, as might be the case if it comes from a table, then the parser will try to coerce it to become text: ! tgl=> SELECT substr(varchar '1234', 3); ! substr ! -------- ! 34 (1 row) which is transformed by the parser to become ! tgl=> SELECT substr(text(varchar '1234'), 3); ! substr ! -------- ! 34 (1 row) --- 648,665 ---- If the string is declared to be of type varchar, as might be the case if it comes from a table, then the parser will try to coerce it to become text: ! regression=# SELECT rpad(varchar '1234', 7, 'x'); ! rpad ! --------- ! 1234xxx (1 row) which is transformed by the parser to become ! regression=# SELECT rpad(text(varchar '1234'), 7, 'x'); ! rpad ! --------- ! 1234xxx (1 row) *************** *** 678,695 **** And, if the function is called with an int4, the parser will try to convert that to text: ! tgl=> SELECT substr(1234, 3); ! substr ! -------- ! 34 (1 row) which actually executes as ! tgl=> SELECT substr(text(1234), 3); ! substr ! -------- ! 34 (1 row) This succeeds because there is a conversion function text(int4) in the --- 678,695 ---- And, if the function is called with an int4, the parser will try to convert that to text: ! regression=# SELECT rpad(1234, 7, 'x'); ! rpad ! --------- ! 1234xxx (1 row) which actually executes as ! regression=# SELECT rpad(text(1234), 7, 'x'); ! rpad ! --------- ! 1234xxx (1 row) This succeeds because there is a conversion function text(int4) in the
Re: new typeconv example (was [HACKERS] More outdated documentation)
От:
Peter Eisentraut <peter_e@gmx.net>
Дата:
Hmm, I already fixed all the outdated examples in my local copy. Sorry that I forgot to mention it. Joe Conway writes: > Peter Eisentraut wrote: > > Example 7-5 in the User's Guide is also outdated, because there is now a > > function substr for bytea, so the mechanics the example tries to > > illustrate are a tad more complicated. New example requested. > > > > Here's a new example, as requested. > > Joe > -- Peter Eisentraut peter_e@gmx.net