-
Notifications
You must be signed in to change notification settings - Fork 23
Error on 'count(*)' #12
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
Comments
Sorry, if you are not using FDW, then you should use countall(*) function instead of count(). |
countall(*) is also wrong.
|
Sorry, for confusing you. |
Ok, I am a little confused.
attention please. The value of column_int8 is NULL where pk_column=67 and pk_column=30 After populating. The result that I want is this: But when I execute de query on VOPS table, I get this :
Look, The count is 1. But if I add other aggregate function. The result of 'count(*)' is different:
** Look The count changed to 64. I don't know why this happens** According to your suggestion. I use count(column_int8).
Obviously, count(*) and count(column_int2) are wrong. count(column_int8) is only total number of Non-null values. count(pk_column) is correct. If I query the total row number of a group, no matter whether a column is null or not. I can ues count(*) or count(column_int2) in std_table which is a normal table. But in the VOPS table I shoud count a column which does not contains null value? Actually, we probably have no idea which column does not contains null value. So In this situation, what should we do to count all? Best regards, thank you. |
Yes, you should use count(pk_column) or any other non-null column. So if you now get updated VOPS version from repository, then your query will work correctly without any hacks: SELECT column_int2,column_int4,sum(column_int8),count(*) FROM vops_table_gb WHERE column_int8>0 GROUP BY column_int2,column_int4 ORDER BY column_int2,column_int4;
column_int2 | column_int4 | sum | count
-------------+-------------+-----+-------
0 | 1 | 52 | 1
1 | 0 | 71 | 1
1 | 1 | 92 | 1
2 | 1 | 7 | 1
2 | 2 | 50 | 1
3 | 2 | 33 | 1
4 | 4 | 118 | 2
5 | 3 | 100 | 2
(8 rows) |
I reinstalled the Linux operating system,reinstalled postgresql and re-download VOPS to make sure everything is ok.
I execute the sql that you provid.
My understanding is that using count(*) must specify where conditions . Is this right? If this understanding is right, then what is the meaning of But I Think |
Did you call vops_initialize() before running this queries? |
Yes, I did call vops_initialize() before every query. 1:
2:
3:
Please look at the the second and third query. The result of Best regards, thank you. |
It is necessary to call vops_initialize() only once when you start new backend. Based on your results mentioned above, it seems to me that for some reasons you have not upgraded VOPS extension. Please notice that you need to call "make install" in VOPS directory and check that library is installed in proper place. You should also restart backend, drop and recreate VOPS extension. SELECT column_int2,column_int4,sum(column_int8),countany(column_int8) FROM vops_table_gb GROUP BY column_int2,column_int4; countany is new function I have added. It should return correct count number doesn't matter whether there are NULL values in specified column. Unfortunately third query will not be correctly transformed - there are no any aggregates on VOPS columns, so VOPS has no idea that count(*) should be replaced with countany in this case. You can to call contany(column_int8) explicitly here,. |
Hello,
Another error was found when I execute 'count(*)', Please check.
1:
VOPS_TEST=# create table std_table(pk_column int2,column_int2 int2, column_int4 int4, column_int8 int8);
CREATE TABLE
2:
INSERT INTO std_table VALUES(random()*100,2,5,random()*1000);
INSERT INTO std_table VALUES(random()*100,2,5,random()*1000);
INSERT INTO std_table VALUES(random()*100,7,3,random()*1000);
3:
VOPS_TEST=# table std_table;
pk_column | column_int2 | column_int4 | column_int8
-----------+-------------+-------------+-------------
68 | 2 | 5 | 339
92 | 2 | 5 | 607
90 | 7 | 3 | 372
(3 rows)
4:
VOPS_TEST=# create table vops_table_gb(pk_column vops_int2,column_int2 int2, column_int4 int4, column_int8 vops_int8);
CREATE TABLE
5:
VOPS_TEST=# select populate(destination:='vops_table_gb'::regclass, source:='std_table'::regclass, sort := 'column_int2,column_int4');
populate
----------
3
(1 row)
6:
VOPS_TEST=# select column_int2,column_int4,column_int8 from vops_table_gb;
column_int2 | column_int4 | column_int8
-------------+-------------+-------------------------------------------------------------------------
2 | 5 | {339,607,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,}
7 | 3 | {372,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,}
(2 rows)
7:
VOPS_TEST=# SELECT column_int2,column_int4,sum(column_int8),count(*) FROM std_table GROUP BY column_int2,column_int4 ORDER BY column_int2,column_int4;
column_int2 | column_int4 | sum | count
-------------+-------------+-----+-------
2 | 5 | 946 | 2
7 | 3 | 372 | 1
(2 rows)
8:
VOPS_TEST=# SELECT column_int2,column_int4,sum(column_int8),count(*) FROM vops_table_gb GROUP BY column_int2,column_int4 ORDER BY column_int2,column_int4;
column_int2 | column_int4 | sum | count
-------------+-------------+-----+-------
2 | 5 | 946 | 64
7 | 3 | 372 | 64
(2 rows)
The text was updated successfully, but these errors were encountered: