to_number function questions

Started by Cindyover 23 years ago2 messagesgeneral
Jump to latest
#1Cindy
ctmoore@uci.edu

What does to_number do with a string like "123x78" ? Does
it try to convert the whole string? Does it stop at x, giving 123?
Does it drop x? Does it return some sort of failure?

Also, suppose that you give to_number 123, and the second parameter is
"999999" ? Do the extra 9's give any problem (you dn't always know
whether to_number will get 0-99999, so what do you give it in the
formatting string? If it has more 9's in the format string than are
digits in the number, will it pad it?

Sorry for all the q's but the page
http://www.postgresql.org/idocs/index.php?functions-formatting.html
only lists things in tables and does not discuss the sorts of questions
or oddball inputs/exceptions I ask about.

Thanks,
--Cindy
--
ctmoore@uci.edu

#2Karel Zak
zakkr@zf.jcu.cz
In reply to: Cindy (#1)
Re: to_number function questions

On Tue, Sep 17, 2002 at 12:26:57PM -0700, Cindy wrote:

What does to_number do with a string like "123x78" ? Does
it try to convert the whole string? Does it stop at x, giving 123?
Does it drop x? Does it return some sort of failure?

test=# select to_number('123x78', '999x99');
to_number
-----------
12378

test=# select to_number('123x78', '999');
to_number
-----------
123

test=# select to_number('123x78', '999999');
to_number
-----------
12378

test=# select to_number('123xxx78', '999yyy99');
to_number
-----------
12378

Also, suppose that you give to_number 123, and the second parameter is
"999999" ? Do the extra 9's give any problem (you dn't always know
whether to_number will get 0-99999, so what do you give it in the
formatting string? If it has more 9's in the format string than are
digits in the number, will it pad it?

test=# select to_number('123', '99999999999999999999999');
to_number
-----------
123

Sorry for all the q's but the page
http://www.postgresql.org/idocs/index.php?functions-formatting.html
only lists things in tables and does not discuss the sorts of questions
or oddball inputs/exceptions I ask about.

The docs expect that user knows 'psql' and knows method how test wanted
questions before post it to PG lists :-) The patches with better docs are
wanted of course.

Karel

--
Karel Zak <zakkr@zf.jcu.cz>
http://home.zf.jcu.cz/~zakkr/

C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz