This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db=> CREATE FUNCTION toint(varchar) | |
RETURNS integer | |
STRICT IMMUTABLE LANGUAGE SQL AS | |
'SELECT cast($1 as integer);'; | |
db=> \d public.items | |
Column | Type | |
-----------------------+------------------------ | |
... | |
description | character varying(255) | |
... | |
lastvalue | character varying(255) | |
... | |
db=> select sum(lastvalue) from public.items where description like '%YOUR ITEM%' and lastvalue is not null; | |
ERROR: function sum(character varying) does not exist | |
LINE 1: select sum(lastvalue) from public.items where description li... | |
db=> select sum(toint(lastvalue)) from public.items where description like '%YOUR ITEM%' and lastvalue is not null; | |
sum | |
------- | |
100000 | |
(1 row) |
Источник решения: stackoverflow.com.
Комментариев нет:
Отправить комментарий