pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedwarning for subquery that references a table but not its columns
2+ messages / 2 participants
[nested] [flat]
* warning for subquery that references a table but not its columns
@ 2018-01-18 21:05 Seamus Abshere <seamus@abshere.net>
2018-01-19 03:49 ` Re: warning for subquery that references a table but not its columns Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 2+ messages in thread
From: Seamus Abshere @ 2018-01-18 21:05 UTC (permalink / raw)
To: pgsql-general
I almost got bit by this today:
=> select email from subscribed where email not in (select email from tracks);
email
-------
(0 rows)
=> select email from subscribed where email not in (select tracks.email from tracks);
ERROR: column tracks.email does not exist
LINE 1: ... email from subscribed where email not in (select tracks.ema...
(the "tracks" table doesn't have an "email" column, so the first query is just meaningless)
Should there be a warning for the first query that you reference "tracks" in a subquery but don't use any columns from it?
--
Seamus Abshere, SCEA
https://www.faraday.io
https://github.com/seamusabshere
https://linkedin.com/in/seamusabshere
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: warning for subquery that references a table but not its columns
2018-01-18 21:05 warning for subquery that references a table but not its columns Seamus Abshere <seamus@abshere.net>
@ 2018-01-19 03:49 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2018-01-19 03:49 UTC (permalink / raw)
To: Seamus Abshere <seamus@abshere.net>; +Cc: pgsql-general
Seamus Abshere <seamus@abshere.net> writes:
> Should there be a warning for the first query that you reference "tracks" in a subquery but don't use any columns from it?
Unfortunately, outer references in subqueries are perfectly legal per SQL
standard, and also often essential.
If we were to invent a "SET training_wheels = on" option, it would surely
include some warnings in this area, although I'm not sure exactly what the
triggering conditions ought to be. But there are lots of ways to mess
yourself up in SQL; I don't think subqueries are that much worse than
some other gotchas.
regards, tom lane
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2018-01-19 03:49 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-01-18 21:05 warning for subquery that references a table but not its columns Seamus Abshere <seamus@abshere.net>
2018-01-19 03:49 ` Tom Lane <tgl@sss.pgh.pa.us>
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