Re: How to create function returning numeric from string containing percent character

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: How to create function returning numeric from string containing percent character
Дата
Msg-id CAKFQuwb+Mjc3QLxiP5dKD0qK9163uZXc1EtuECFZR=qR_WQH+Q@mail.gmail.com
обсуждение исходный текст
Ответ на How to create function returning numeric from string containing percent character  ("Andrus" <kobruleht2@hot.ee>)
Список pgsql-general
On Wed, Jul 22, 2020 at 3:50 AM Andrus <kobruleht2@hot.ee> wrote:
val function should return numeric value from string up to first non-digit character, considering first decimal point also:

    val('1,2TEST')  should return 1.2
    val('1,2,3')  should return 1.2
    val('-1,2,3')  should return -1.2

    SELECT coalesce(nullif('0'||substring(Translate($1,',','.'), '^-?[0-9]+\.?[0-9]*$'),''),'0')::numeric;
select val('1,2%')
How to force it to return 1.2 ?

It should work starting from Postgres 9.0

Removing the $ from your regexp pattern should work for the 4 provided examples.

You cannot remove stuff from the end of a string if you require that the end of said string match what you want to return.

David J.

В списке pgsql-general по дате отправления:

Предыдущее
От: "David G. Johnston"
Дата:
Сообщение: Re: CASCADE/fkey order
Следующее
От: Surya Widyanto
Дата:
Сообщение: Re: Slow or Cannot Connect to PostgreSQL Instance Service on Windows 10