Author |
Message
|
Jenum |
Posted: Thu Sep 03, 2015 9:07 am Post subject: How to determine scalar type of field in ESQL |
|
|
Novice
Joined: 13 Nov 2012 Posts: 24
|
Hi all!
I have problem: i need check, whether field is string or number (in the incoming JSON-message). Is it possible?
I have only one idea: use CAST(... AS DOUBLE) on this field and catch exception - if it is, then field is string. But it no very good solution... |
|
Back to top |
|
 |
smdavies99 |
Posted: Thu Sep 03, 2015 10:03 am Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
Could it be a string that contains numbers and a '.'?
To test if a field contains only numeric digits and a '.' then you can use the solution described here
http://mqseries.net/phpBB/viewtopic.php?t=51183&sid=1b332f7d593c914f4274bf7b64adf890 _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
timber |
Posted: Thu Sep 03, 2015 10:54 am Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
Quote: |
i need check, whether field is string or number (in the incoming JSON-message). |
Is this for validation, or some other purpose? |
|
Back to top |
|
 |
Jenum |
Posted: Thu Sep 03, 2015 11:03 pm Post subject: |
|
|
Novice
Joined: 13 Nov 2012 Posts: 24
|
timber, other purpose: processing of the field depends on its value  |
|
Back to top |
|
 |
smdavies99 |
Posted: Fri Sep 04, 2015 12:46 am Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
Jenum wrote: |
timber, other purpose: processing of the field depends on its value  |
So you can check to see if the field contains the right sort of characters as I described above. Then if that passes you can cast the string to a field of the right type knowing that it will not cause an exception. _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Sep 04, 2015 4:41 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Jenum wrote: |
timber, other purpose: processing of the field depends on its value  |
That doesn't seem like a good design for the data structure. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
timber |
Posted: Fri Sep 04, 2015 7:29 am Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
Quote: |
I have only one idea: use CAST(... AS DOUBLE) on this field and catch exception - if it is, then field is string. But it no very good solution... |
Sounds like a reasonable solution to me. What's wrong with it?
[/quote] |
|
Back to top |
|
 |
mgk |
Posted: Sat Sep 05, 2015 5:57 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Use the DEFAULT clause on the CAST - is supresses the exception and sets the result to the value of the DEFAULT specified.
Kind regards, _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
|