Re: Table column with numeric and string values

Поиск
Список
Период
Сортировка
От soumitra bhandary
Тема Re: Table column with numeric and string values
Дата
Msg-id MA0PR01MB60063012056B892E851A73FBE0D99@MA0PR01MB6006.INDPRD01.PROD.OUTLOOK.COM
обсуждение исходный текст
Ответ на Table column with numeric and string values  (Firthouse banu <penguinsfairy@gmail.com>)
Ответы Re: Table column with numeric and string values  (pramod kg <pramod11287@gmail.com>)
Список pgsql-admin
Hi, 

You can try to filter data with some function and function code should be like below . 

CREATE OR REPLACE FUNCTION "sys"."isnumeric"(text)
RETURNS "pg_catalog"."bool" AS $BODY$
DECLARE x NUMERIC;
BEGIN    x = $1::NUMERIC;    RETURN TRUE;
EXCEPTION WHEN others THEN    RETURN FALSE;
END;
$BODY$  LANGUAGE 'plpgsql' IMMUTABLE STRICT  COST 100
;


Try this out 


Thanks,
Soumitra

Sent from my iPhone

On 13-Sep-2021, at 2:25 PM, Firthouse banu <penguinsfairy@gmail.com> wrote:

Hello everyone, 

Need a urgent help.

I have a table sqlt_data with column strungvalue  as character varying , in that column we have both numbers and string. 
I have function which pulls this values and do round(avg(string value::numeric,2),0) . Am able to run the function fine with numeric values and it is obvious but for string values getting error. How to make this function work with string values . As far as I know avg or round cannot be done on string values. Please advise.

Thanks
Firthouse 

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

Предыдущее
От: Firthouse banu
Дата:
Сообщение: Table column with numeric and string values
Следующее
От: pramod kg
Дата:
Сообщение: Re: Table column with numeric and string values