Return Only number from a string if it contains numbers

后端 未结 3 1479
深忆病人
深忆病人 2021-01-28 07:21

For example,
string is abc123CD need to find out a method to read only numbers in the string
i.e.

  select a_postgres_function(\'a         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-28 08:20

    As per ntalbs's Answer


    Wrap that query into a Function

    create or replace function shownums(text) returns integer as 
    $$
    select (regexp_matches($1,'\d+'))[1]::int; 
    $$
    language sql;
    

提交回复
热议问题