CTE must be aliased as itself, otherwise "no data source matches prefix" error

Why does the last of these 4 queries result in an error?

no data source matches prefix

with a as (select 1 as testval) select * from a;
  testval  
+---------+
        1  

with a as (select 1 as testval) select testval from a;
  testval  
+---------+
        1  

with a as (select 1 as testval) select a.testval from a as a;
  testval  
+---------+
        1  

with a as (select 1 as testval) select a.testval from a;
pq: no data source matches prefix: a

I’m using CockroachDB OSS v19.1.3.

THANK YOU

Hi Steven,

Thank you for providing detailed information. It helped us research this error.

I confirmed that it is a bug in version 19.1.
I logged it in Github for our team to review: 43963

The current available workaround is to upgrade to version 19.2.2.

Regards,
Florence