By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,852 Members | 2,200 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,852 IT Pros & Developers. It's quick & easy.

Determine if a string is digit

P: n/a
Hello list,

That's my question, I can't figure out a way to know if a given string
is digit, soemthing like this:

ISDIGIT("ARWA") = False
ISDIGIT("5334") = True

If anyone know a way to get that done, I'll appreciate the help.

--
Josué Maldonado.


---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Josué Maldonado <jo***@lamundial.hn> writes:
Hello list,

That's my question, I can't figure out a way to know if a given string is
digit, soemthing like this:
ISDIGIT("ARWA") = False
ISDIGIT("5334") = True

If anyone know a way to get that done, I'll appreciate the help.


create function isdigit(text) returns boolean as '
select $1 ~ ''^(-)?[0-9]+$'' as result
' language sql;

masm=# select isdigit('ARWA');
isdigit
---------
f
(1 row)

masm=# select isdigit('5334');
isdigit
---------
t
(1 row)

Regards,
Manuel.

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 12 '05 #2

P: n/a
Thanks Manuel,

It works nice!

Manuel Sugawara wrote:
Josué Maldonado <jo***@lamundial.hn> writes:

Hello list,

That's my question, I can't figure out a way to know if a given string is
digit, soemthing like this:
ISDIGIT("ARWA") = False
ISDIGIT("5334") = True

If anyone know a way to get that done, I'll appreciate the help.

create function isdigit(text) returns boolean as '
select $1 ~ ''^(-)?[0-9]+$'' as result
' language sql;

masm=# select isdigit('ARWA');
isdigit
---------
f
(1 row)

masm=# select isdigit('5334');
isdigit
---------
t
(1 row)

Regards,
Manuel.

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

--
Josué Maldonado.

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.