Re: Bug or stupidity - Mailing list pgsql-general

From Thomas Hallgren
Subject Re: Bug or stupidity
Date
Msg-id 417ECC6E.3020507@mailblocks.com
Whole thread Raw
In response to Re: Bug or stupidity  (Martijn van Oosterhout <kleptog@svana.org>)
Responses Re: Bug or stupidity  (Martijn van Oosterhout <kleptog@svana.org>)
List pgsql-general
Martijn,
 > Do you have a better
> suggestion, other than forbidding the currently allowed syntax?
>
Yes I do.

We agree that my second example should be disallowed since the semantics
of the FROM clause is different for a DELETE so the "add_missing_from"
is actually not adding to a FROM clause, it is guessing the scope for
the predicate. I assume the same is true for an UPDATE where there is no
FROM at all.

My suggestion is that we rename the add_missing_from to:

update_delete_autoscope

and that this option has no effect on SELECT clauses. It would be more
or less harmless to have it enabled by default.

Perhaps the add_missing_from should remain but then only affect the
SELECT and as disabled by default.

> Anyway, I think the reasoning so far is, the default stays as it is
> until someone comes up with a non-confusing way of adding a real FROM
> clause to DELETEs.
 >
SQL already defines a stright forward way to do that. Consider the
following PostgreSQL syntax:

DELETE FROM first_table
   WHERE first_table.id = second_table.xid AND second_table.foo > 4

in standard SQL this would be:

DELETE FROM first_table x
   WHERE x.id IN (SELECT y.xid FROM second_table y WHERE y.foo > 4)

The number of characters is almost the same in both statements even for
a very simple WHERE clause thanks to aliasing. The benefits of aliasing
increases as the WHERE clause gets more complicated.

For composite keys or other non key based relationships, the EXISTS
clause can be used.

Why confuse people with yet another syntax?

Regards,
Thomas Hallgren

pgsql-general by date:

Previous
From: Devrim GUNDUZ
Date:
Subject: Re: (S)RPMs for PostgreSQL 7.2.6, 7.3.8 and 7.4.6 are
Next
From: "Naeem Bari"
Date:
Subject: Re: Newbie question about escaping in a function