pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: tosites2019@gmail.com
Subject: BUG #15783: Fail to select with a function in FROM clause plus another table
Date: Sun, 28 Apr 2019 04:09:18 +0000
Message-ID: <15783-37dcbcb4c20f231d@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      15783
Logged by:          To Sites
Email address:      tosites2019@gmail.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.



view thread (2+ messages)  latest in thread

Message-ID: <15783-37dcbcb4c20f231d@postgresql.org>
Permalink:  ../15783-37dcbcb4c20f231d@postgresql.org/
Also on:    postgresql.org/message-id/15783-37dcbcb4c20f231d@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, tosites2019@gmail.com
  Subject: Re: BUG #15783: Fail to select with a function in FROM clause plus another table
  In-Reply-To: <15783-37dcbcb4c20f231d@postgresql.org>
  References: <15783-37dcbcb4c20f231d@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox