I have a hard time understanding why I can refer to the output columns in `returns table(col type)`.

There is a subtle bug in the below code, the `order by` var refers to `res` in `returns`, not to `data1` which we aliased to `res`. `res` in `where` is always null and we get 0 rows.

Why can I refer to the column name in output?  

In what cases do I want this?

```
CREATE OR REPLACE FUNCTION public.test(var INTEGER)
RETURNS table(res int )
LANGUAGE plpgsql
AS $function$
begin
    return query 
    select data1 res 
    from table_with_data 
    where res < var;
end
$function$

```