| From: | PG Bug reporting form <noreply(at)postgresql(dot)org> | 
|---|---|
| To: | pgsql-bugs(at)lists(dot)postgresql(dot)org | 
| Cc: | tosites2019(at)gmail(dot)com | 
| Subject: | BUG #15783: Fail to select with a function in FROM clause plus another table | 
| Date: | 2019-04-28 04:09:18 | 
| Message-ID: | 15783-37dcbcb4c20f231d@postgresql.org | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-bugs | 
The following bug has been logged on the website:
Bug reference:      15783
Logged by:          To Sites
Email address:      tosites2019(at)gmail(dot)com
PostgreSQL version: 10.7
Operating system:   Windows 8.1
Description:        
-- FAIL
  select m.nome socio, p.tipo, sum(c.valor * m.percentual / 100) valor
  from contas_pagas('2019-04-01', '2019-04-30', 'R') c, medico m
  inner join planoconta p on (c.cod_planoconta = p.cod)
  where (m.percentual > 0)
  group by m.nome, p.tipo
  -- ERROR
  -- SQL Error [42P01]: ERROR: invalid reference to FROM-clause entry for
table "c"
  -- Hint: There is an entry for table "c", but it cannot be referenced from
this part of the query.
  -- Position: 169
  -- WORKS
  select m.nome socio, p.tipo, sum(c.valor * m.percentual / 100) valor
  from contas_pagas('2019-04-01', '2019-04-30', 'R') c
  inner join planoconta p on (c.cod_planoconta = p.cod)
  cross join medico m
  where (m.percentual > 0)
  group by m.nome, p.tipo
In other words, we need to use cross join instead of put all tables in FROM
clause, if one of these tables was a function that returns a table.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2019-04-28 04:55:12 | Re: BUG #15783: Fail to select with a function in FROM clause plus another table | 
| Previous Message | Peter Geoghegan | 2019-04-28 03:28:04 | Re: BUG #15745: WAL References Invalid Pages...that eventually resolves |