Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Result type of AVG over BIGINT column results in type INT128 #6845

Closed
mrotteveel opened this issue Jun 5, 2021 · 5 comments
Closed

Result type of AVG over BIGINT column results in type INT128 #6845

mrotteveel opened this issue Jun 5, 2021 · 5 comments

Comments

@mrotteveel
Copy link
Member

The result type of aggregate function AVG over a BIGINT column results in a column type INT128. This makes no sense because the average can never exceed the maximum of the input type. Similarly, AVG over INTEGER should return INTEGER, not BIGINT, etc.

SQL> set sqlda_display on;
SQL> select avg(cast(1 as bigint)) from rdb$database;

INPUT message field count: 0

OUTPUT message field count: 1
01: sqltype: 32752 INT128 Nullable scale: 0 subtype: 0 len: 16
  :  name: AVG  alias: AVG
  : table:   owner:

                                          AVG
=============================================
                                            1

SQL>

Expected would be sqltype: 580 INT64

@mrotteveel
Copy link
Member Author

mrotteveel commented Jun 5, 2021

This also applies for NUMERIC/DECIMAL : for precision < 9 it expands to precision 18, for precision between 10 and 18 it expands precision to 38.

@mrotteveel
Copy link
Member Author

Also DECFLOAT(16).

@AlexPeshkoff AlexPeshkoff self-assigned this Jun 7, 2021
@AlexPeshkoff
Copy link
Member

I doubt it's worth changing old datatypes - just cause incompatibilities in old applications. What about bigint => int128 & DECFLOAT(16 => 34) I will fix - just wait a little, may be somebody will see problems with it.

@mlazdans
Copy link

Agree. And this "bug" crashes PHP extension too even on databases that never use INT128 type.

@mrotteveel
Copy link
Member Author

mrotteveel commented Jun 11, 2021

@mlazdans The workaround is to configure DataTypeCompatibility to 3.0 (or 2.5) in either firebird.conf or databases.conf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment