计算名称为 'count' returns 多行的列。为什么?

Count column with name 'count' returns multiple rows. Why?

我不明白为什么这个查询:

select count(base.*) from mytable base;

return 多行。

select count(1) from mytable base;

return正确计数。

有一列名称为 count

谁能解释一下这种行为?

这是来自架构的信息:

table_catalog,table_schema,table_name,column_name,ordinal_position,column_default,is_nullable,data_type,character_maximum_length,character_octet_length,numeric_precision,numeric_precision_radix,numeric_scale,datetime_precision,interval_type,interval_precision,character_set_catalog,character_set_schema,character_set_name,collation_catalog,collation_schema,collation_name,domain_catalog,domain_schema,domain_name,udt_catalog,udt_schema,udt_name,scope_catalog,scope_schema,scope_name,maximum_cardinality,dtd_identifier,is_self_referencing,is_identity,identity_generation,identity_start,identity_increment,identity_maximum,identity_minimum,identity_cycle,is_generated,generation_expression,is_updatable
mydatabase,vcs,mytable,controlepunt,1,,YES,text,,1073741824,,,,,,,,,,,,,,,,mydatabase,pg_catalog,text,,,,,1,NO,NO,,,,,,,NEVER,,YES
mydatabase,vcs,mytable,norm,2,,YES,text,,1073741824,,,,,,,,,,,,,,,,mydatabase,pg_catalog,text,,,,,2,NO,NO,,,,,,,NEVER,,YES
mydatabase,vcs,mytable,fout,3,,YES,text,,1073741824,,,,,,,,,,,,,,,,mydatabase,pg_catalog,text,,,,,3,NO,NO,,,,,,,NEVER,,YES
mydatabase,vcs,mytable,count,4,,YES,bigint,,,64,2,0,,,,,,,,,,,,,mydatabase,pg_catalog,int8,,,,,4,NO,NO,,,,,,,NEVER,,YES
mydatabase,vcs,mytable,id,5,,YES,bigint,,,64,2,0,,,,,,,,,,,,,mydatabase,pg_catalog,int8,,,,,5,NO,NO,,,,,,,NEVER,,YES

这不是答案 - 用它来扩展 OP 的示例。它似乎与聚合函数无关:

t=# create table s91("count" int);
CREATE TABLE
Time: 38.981 ms
t=# insert into s91 values (1),(2),(3);
INSERT 0 3
Time: 13.929 ms
t=# select count(base.*) from s91 base;
 count 
-------
     1
     2
     3
(3 rows)

t=# alter table s91 rename COLUMN a to "manah_manah";
ALTER TABLE
Time: 1.025 ms
t=# select manah_manah(s91.*) from s91;
 manah_manah 
-------------
           1
           2
           3
(3 rows)

更新:似乎column(alias_name)是一个有效的语法:

s=# with c(a,b) as (values(1,2),(2,3))
select a(c),(c).a from c;
 a | a 
---+---
 1 | 1
 2 | 2
(2 rows)

这种风格显然被称为功能符号

它使 table.colcol(table) 等价。

tabletable.*return相同的一组列。

这个问题有更多相关信息:Using functional notation in PostgreSQL queries instead of dot notation

在 postgresql 文档中:https://www.postgresql.org/docs/9.1/static/xfunc-sql.html

Another option is to use functional notation for extracting an attribute. The simple way to explain this is that we can use the notations attribute(table) and table.attribute interchangeably.