Re: Document behaviour of failed sub queries

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: jackbicknell(at)gmail(dot)com, Pg Docs <pgsql-docs(at)lists(dot)postgresql(dot)org>
Subject: Re: Document behaviour of failed sub queries
Date: 2021-06-28 15:40:29
Message-ID: CAKFQuwbiDS7M8qNDwQeUm401ZU4aUUAwXoEC=E8xVjmO1pj0QA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

On Mon, Jun 28, 2021 at 8:34 AM PG Doc comments form <noreply(at)postgresql(dot)org>
wrote:

> For example:
> UPDATE table1 SET status='expired' WHERE id in (SELECT wrong_id IN table2)
>
> This will update every row in table1if wrong_id doesn't exist, ignoring the
> ERROR: column "wrong_id" does not exist from the subquery.
>

The subquery never provokes that error by virtue of the fact it is a
subquery. It's only if you run that as a standalone query do you see the
error. This is because correlated subqueries are a thing (and, yes, they
are documented).

https://wiki.postgresql.org/wiki/FAQ#Why_doesn.27t_PostgreSQL_report_a_column_not_found_error_when_using_the_wrong_name_in_a_subquery.3F

David J.

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message David G. Johnston 2021-06-28 15:46:02 Re: Document behaviour of failed sub queries
Previous Message PG Doc comments form 2021-06-28 15:37:15 SETOF specification and default behavior (CREATE FUNCTION)