Unexpected behaviour for GROUP BY query CREATE TABLE public.temp (
   id integer, 
   a integer, 
   b integer, 
   x integer
);

select x, a, b
    from temp
group by id, a, b;

ends up with expected error:

ERROR:  column &quot;temp.x&quot; must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: select x, a, b
               ^


However, after adding primary key:
ALTER TABLE ONLY temp ADD  PRIMARY KEY (id);

... the previous SELECT query runs without error.
Why can column x now be used without aggregation?
Is the behaviour documented?
GROUP BY by primary key column causes each row to become a separate group. In this case the column not included into grouping / aggregating has only one value within the group, so this value may be returned without ambiguity.
If there is no primary column / expression as a part of grouping expression then server must consider that there may be more than one value for a group, and it generates error because of possible ambiguity.
In general the fact that the error is not generated is an extension it seems...
If PK is a part of grouping expression than formally all another parts are excess. I.e. if id is PK then group by id, group by id,a,b,x, group by id,a,b, group by id,b,x, group by id,a,x, ... will have the same meaning and effect.
But the best practice is to use an aggregate function for each non-groupby column / expression in any case.