Can anyone tell me the query to check whether a string is a number(double precision). It should return true if the string is number. else it should return false.
consider :
s1 character varying; s2 character varying; s1 ='12.41212' => should return true s2 = 'Service' => should return false
A simple approach to check if a Python string contains a number is to verify every character in the string using the string isdigit() method. Once that's done we get a list of booleans and if any of its elements is True that means the string contains at least one number.
PostgreSQL supports the NUMERIC type for storing numbers with a very large number of digits. Generally NUMERIC type are used for the monetary or amounts storage where precision is required. Syntax: NUMERIC(precision, scale) Where, Precision: Total number of digits.
Like operator is used to find or retrieve data to specified matching patterns. % (wildcard) is used to get all characters. % it is used to retrieve one or more characters from the database. _ (Underscore) is used to match any number of single characters.
I think the easiest way would be a regular expression match:
select '12.41212' ~ '^[0-9\.]+$' => true select 'Service' ~ '^[0-9\.]+$' => false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With