N
N
newbie_python2021-09-07 17:07:33
PostgreSQL
newbie_python, 2021-09-07 17:07:33

Why does "Final statement returns bigint instead of integer" error occur in SQL function?

Good afternoon! Tell me, please, what could cause an error when trying to create a table function in the POSTGRESQL database?:

ERROR:  return type mismatch in function declared to return record
DETAIL:  Final statement returns bigint instead of integer at column 2.


The data types of the attributes in the source (root) tables match what I have in the query, perhaps something is wrong in the structure of the function itself? I rummaged through Google and did not find a solution :(

PS I tried to "play around" with these attributes and with this type of request beginning (removed most of the attributes and changed the type):
create or replace function "bd"."function"("reg" int4, "date" date)
  returns table("4.1" int4, "5.1" bigint, ) as $body$


There is already another error:
ERROR:  return type mismatch in function declared to return record
DETAIL:  Final statement returns too many columns.


The request itself: https://ps.tmpc.ru/6927e42610e7

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2021-09-07
@newbie_python

The data types as they are declared in the output parameters of the function do not match what you are trying to do in return. Should match each other.
sum in pg13 we have these:

melkij=> \da pg_catalog.sum
                                              Список агрегатных функций
   Схема    | Имя | Тип данных результата | Типы данных аргументов |                     Описание                     
------------+-----+-----------------------+------------------------+--------------------------------------------------
 pg_catalog | sum | numeric               | bigint                 | sum as numeric across all bigint input values
 pg_catalog | sum | double precision      | double precision       | sum as float8 across all float8 input values
 pg_catalog | sum | bigint                | integer                | sum as bigint across all integer input values
 pg_catalog | sum | interval              | interval               | sum as interval across all interval input values
 pg_catalog | sum | money                 | money                  | sum as money across all money input values
 pg_catalog | sum | numeric               | numeric                | sum as numeric across all numeric input values
 pg_catalog | sum | real                  | real                   | sum as float4 across all float4 input values
 pg_catalog | sum | bigint                | smallint               | sum as bigint across all smallint input values

As you can see, there is not a single option that would return int4
Final statement returns too many columns really need to be explained? Or is it already said in direct English?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question