Re: Add Missing From?

Lists: pgsql-hackers
From: Josh Berkus <josh(at)agliodbs(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Add Missing From?
Date: 2004-08-08 23:26:49
Message-ID: 200408081626.49494.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom, Et Al:

Going over the .conf, I just noticed that add_missing_from is still set to
True in postgresql.conf.sample. By my memory of our discussion, this
option was introduced in 7.4 and was to be set to False by default in 8.0.
Can we switch it to False?

BTW, the reason for setting it to false is that it's not SQL-standard and
often leads to "silent failures"; that is, users getting results they don't
expect because they left out a table name.

--
-Josh Berkus
Aglio Database Solutions
San Francisco


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: josh(at)agliodbs(dot)com
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-09 00:46:45
Message-ID: 23902.1092012405@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Josh Berkus <josh(at)agliodbs(dot)com> writes:
> Going over the .conf, I just noticed that add_missing_from is still set to
> True in postgresql.conf.sample. By my memory of our discussion, this
> option was introduced in 7.4 and was to be set to False by default in 8.0.
> Can we switch it to False?

I don't see anything in the current docs warning that such a change is
afoot. We have insisted on one release cycle's warning for smaller
things than this ...

Personally I don't mind (but bear in mind that the regression tests will
likely need fixes).

regards, tom lane


From: Josh Berkus <josh(at)agliodbs(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-09 01:44:32
Message-ID: 200408081844.32112.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom,

> I don't see anything in the current docs warning that such a change is
> afoot. We have insisted on one release cycle's warning for smaller
> things than this ...

Ok. Can we put a warning in, then? Where should we put it?

--
Josh Berkus
Aglio Database Solutions
San Francisco


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-09 02:32:38
Message-ID: 1374.1092018758@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Josh Berkus <josh(at)agliodbs(dot)com> writes:
>> I don't see anything in the current docs warning that such a change is
>> afoot. We have insisted on one release cycle's warning for smaller
>> things than this ...

> Ok. Can we put a warning in, then? Where should we put it?

In the description of add_missing_from, I think.

regards, tom lane


From: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-09 02:32:52
Message-ID: 200408082232.52508.xzilla@users.sourceforge.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sunday 08 August 2004 21:44, Josh Berkus wrote:
> Tom,
>
> > I don't see anything in the current docs warning that such a change is
> > afoot. We have insisted on one release cycle's warning for smaller
> > things than this ...
>
> Ok. Can we put a warning in, then? Where should we put it?

AFAIR this is still the only way to do updates on joined tables, a feature
that IIRC is in the sql spec (and certianly in other rdbms') that we do not
support. Until we come up with a solution for that, I think our current
behavior of defaulting on and emiting a warning upon occurance is the right
way to go.

--
Robert Treat
Build A Better Lamp :: Linux Apache {middleware} PostgreSQL


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>
Cc: Josh Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-09 02:36:21
Message-ID: 1720.1092018981@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robert Treat <xzilla(at)users(dot)sourceforge(dot)net> writes:
> AFAIR this is still the only way to do updates on joined tables, a feature
> that IIRC is in the sql spec (and certianly in other rdbms') that we do not
> support.

I think you're wrong on both counts --- we do support UPDATE FROM, and
it's not in the spec.

What we don't have is an equivalent syntax for DELETE, and you're right
that we probably ought to offer that before we deprecate add_missing_from.

regards, tom lane


From: Josh Berkus <josh(at)agliodbs(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-09 02:48:23
Message-ID: 200408081948.23239.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robert, Tom,

> I think you're wrong on both counts --- we do support UPDATE FROM, and
> it's not in the spec.

I can verify that it's not in SQL92. Unless you've got a place they added a
different syntax in 99 or 2003, Robert?

> What we don't have is an equivalent syntax for DELETE, and you're right
> that we probably ought to offer that before we deprecate add_missing_from.

Hmmm. What would that look like?

DELETE FROM table
{FROM | WITH | USING | ?? }
WHERE ...

I think we don't have this mainly because, what word do we use?

--
Josh Berkus
Aglio Database Solutions
San Francisco


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-09 03:16:02
Message-ID: 4467.1092021362@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Josh Berkus <josh(at)agliodbs(dot)com> writes:
> Hmmm. What would that look like?

> DELETE FROM table
> {FROM | WITH | USING | ?? }
> WHERE ...

> I think we don't have this mainly because, what word do we use?

Yup, eggzackle. The implementation would really be trivial, but
previous discussion hung up on the problem of finding a syntax
people liked ...

regards, tom lane


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Josh Berkus <josh(at)agliodbs(dot)com>, Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-09 03:31:58
Message-ID: 200408090331.i793VwA10562@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> Josh Berkus <josh(at)agliodbs(dot)com> writes:
> > Hmmm. What would that look like?
>
> > DELETE FROM table
> > {FROM | WITH | USING | ?? }
> > WHERE ...
>
> > I think we don't have this mainly because, what word do we use?
>
> Yup, eggzackle. The implementation would really be trivial, but
> previous discussion hung up on the problem of finding a syntax
> people liked ...

Agreed, but are we ever going to find any better solution than just
picking one of the suggestions?

I vote for the second FROM.

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073


From: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Josh Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-09 04:12:41
Message-ID: 200408090012.41588.xzilla@users.sourceforge.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sunday 08 August 2004 23:16, Tom Lane wrote:
> Josh Berkus <josh(at)agliodbs(dot)com> writes:
> > Hmmm. What would that look like?
> >
> > DELETE FROM table
> > {FROM | WITH | USING | ?? }
> > WHERE ...
> >
> > I think we don't have this mainly because, what word do we use?
>
> Yup, eggzackle. The implementation would really be trivial, but
> previous discussion hung up on the problem of finding a syntax
> people liked ...
>

Well, as yall have pointed out, the feature is not sql spec (for some reason I
thought it had been put in) so since the update syntax seems quite similar to
oracles, perhaps they can provide a pointer on delete syntax as well? I
can't seem to find my oracle syntax book, anyone have one handy ?

--
Robert Treat
Build A Better Lamp :: Linux Apache {middleware} PostgreSQL


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>
Cc: Josh Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-09 04:29:01
Message-ID: 5431.1092025741@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robert Treat <xzilla(at)users(dot)sourceforge(dot)net> writes:
> Well, as yall have pointed out, the feature is not sql spec (for some
> reason I thought it had been put in) so since the update syntax seems
> quite similar to oracles, perhaps they can provide a pointer on delete
> syntax as well? I can't seem to find my oracle syntax book, anyone
> have one handy ?

Didn't get any Oracle hits in a quick google, but I did find out that
MySQL spells it USING:

DELETE FROM target_tbl USING other_tbls WHERE ...

This isn't a particularly compelling precedent seeing that (a) MySQL
doesn't use our flavor of UPDATE syntax and (b) they only adopted the
above in 4.0.2. But it's better than no precedent. And frankly I
was having a big problem with "DELETE FROM target FROM others ..."
If that's not a recipe for confusion I don't know what is.

regards, tom lane


From: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, Josh Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-09 04:57:53
Message-ID: 41170451.7070001@familyhealth.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

> Didn't get any Oracle hits in a quick google, but I did find out that
> MySQL spells it USING:

You guys can go to otn.oracle.com and register for free to get access to
all the documentation they've ever written. I've got an account there.
I do get the odd oracle magazine sent to me though...

This is the DELETE syntax:

http://download-west.oracle.com/docs/cd/B14117_01/server.101/b10759/statements_8005.htm#sthref6065

This is the text version:

DELETE [ hint ]
[ FROM ]
{ dml_table_expression_clause
| ONLY (dml_table_expression_clause)
}
[ t_alias ]
[ where_clause ]
[ returning_clause ] ;

Where dml_table_expression_clause is:

{ [ schema. ]
{ table
[ { PARTITION (partition)
| SUBPARTITION (subpartition)
}
| @ dblink
]
| { view | materialized view } [ @ dblink ]
}
| ( subquery [ subquery_restriction_clause ] )
| table_collection_expression
}

I can paste more but the way it works is that I can only view each
sub-part of the gammar separately so it's a pain in the butt to copy.

Chris


From: Harald Fuchs <hf0722x(at)protecting(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-09 11:08:14
Message-ID: pusmaw36xt.fsf@srv.protecting.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

In article <5431(dot)1092025741(at)sss(dot)pgh(dot)pa(dot)us>,
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:

> Robert Treat <xzilla(at)users(dot)sourceforge(dot)net> writes:
>> Well, as yall have pointed out, the feature is not sql spec (for some
>> reason I thought it had been put in) so since the update syntax seems
>> quite similar to oracles, perhaps they can provide a pointer on delete
>> syntax as well? I can't seem to find my oracle syntax book, anyone
>> have one handy ?

> Didn't get any Oracle hits in a quick google, but I did find out that
> MySQL spells it USING:

> DELETE FROM target_tbl USING other_tbls WHERE ...

> This isn't a particularly compelling precedent seeing that (a) MySQL
> doesn't use our flavor of UPDATE syntax and (b) they only adopted the
> above in 4.0.2.

Actually, MySQL supports two different syntaxes for multi-table DELETEs:

1. DELETE t1,t2 FROM t1,t2,t3 WHERE t1.id=t2.id AND t2.id=t3.id;
(introduced in MySQL 4.0.0)

2. DELETE FROM t1,t2 USING t1,t2,t3 WHERE t1.id=t2.id AND t2.id=t3.id;
(introduced in MySQL 4.0.2)


From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, Josh Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-09 14:53:05
Message-ID: 41178FD1.8050900@Yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 8/9/2004 12:29 AM, Tom Lane wrote:

> Robert Treat <xzilla(at)users(dot)sourceforge(dot)net> writes:
>> Well, as yall have pointed out, the feature is not sql spec (for some
>> reason I thought it had been put in) so since the update syntax seems
>> quite similar to oracles, perhaps they can provide a pointer on delete
>> syntax as well? I can't seem to find my oracle syntax book, anyone
>> have one handy ?
>
> Didn't get any Oracle hits in a quick google, but I did find out that
> MySQL spells it USING:
>
> DELETE FROM target_tbl USING other_tbls WHERE ...

Feels much more understandable. The second FROM looks like a hickup.

Jan

>
> This isn't a particularly compelling precedent seeing that (a) MySQL
> doesn't use our flavor of UPDATE syntax and (b) they only adopted the
> above in 4.0.2. But it's better than no precedent. And frankly I
> was having a big problem with "DELETE FROM target FROM others ..."
> If that's not a recipe for confusion I don't know what is.
>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose an index scan if your
> joining column's datatypes do not match

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: hf0722x(at)protecting(dot)net
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-09 14:54:54
Message-ID: 14740.1092063294@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Harald Fuchs <hf0722x(at)protecting(dot)net> writes:
> Actually, MySQL supports two different syntaxes for multi-table DELETEs:

> 1. DELETE t1,t2 FROM t1,t2,t3 WHERE t1.id=t2.id AND t2.id=t3.id;
> (introduced in MySQL 4.0.0)

> 2. DELETE FROM t1,t2 USING t1,t2,t3 WHERE t1.id=t2.id AND t2.id=t3.id;
> (introduced in MySQL 4.0.2)

Yeah. I ignored the first, as being so stupid that even the MySQL guys
soon realized what a bad idea it was ;-)

regards, tom lane


From: Josh Berkus <josh(at)agliodbs(dot)com>
To: Jan Wieck <JanWieck(at)Yahoo(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-09 16:53:29
Message-ID: 200408090953.29505.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

People,

> > DELETE FROM target_tbl USING other_tbls WHERE ...
>
> Feels much more understandable. The second FROM looks like a hickup.

Yes, although imagine:

DELETE FROM staff USING users JOIN logons USING (user_id)
WHERE last_logon < ( now() - '6 months');

Not as bad as FROM, but still a bit baffling to look at. Still, I can't
think of anything else that wouldn't require inventing a new reserved word.

Oh, and MySQL's "multi-table deletes": PLEASE tell me that's not
SQL-standard.

--
Josh Berkus
Aglio Database Solutions
San Francisco


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: Jan Wieck <JanWieck(at)Yahoo(dot)com>, Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-09 17:00:33
Message-ID: 16445.1092070833@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Josh Berkus <josh(at)agliodbs(dot)com> writes:
> Oh, and MySQL's "multi-table deletes": PLEASE tell me that's not
> SQL-standard.

It's not.

regards, tom lane


From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-09 17:02:02
Message-ID: 4117AE0A.2090402@Yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 8/9/2004 12:53 PM, Josh Berkus wrote:

> People,
>
>> > DELETE FROM target_tbl USING other_tbls WHERE ...
>>
>> Feels much more understandable. The second FROM looks like a hickup.
>
> Yes, although imagine:
>
> DELETE FROM staff USING users JOIN logons USING (user_id)
> WHERE last_logon < ( now() - '6 months');
>
> Not as bad as FROM, but still a bit baffling to look at. Still, I can't
> think of anything else that wouldn't require inventing a new reserved word.

What about

DELETE FROM staff JOIN users ...

then?

>
> Oh, and MySQL's "multi-table deletes": PLEASE tell me that's not
> SQL-standard.
>

Yes, not standard.

Jan

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jan Wieck <JanWieck(at)Yahoo(dot)com>
Cc: Josh Berkus <josh(at)agliodbs(dot)com>, Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-09 17:07:23
Message-ID: 16580.1092071243@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Jan Wieck <JanWieck(at)Yahoo(dot)com> writes:
> What about
> DELETE FROM staff JOIN users ...
> then?

I don't much care for that, mainly because in my mind "x JOIN y" should
always be semantically equivalent to "y JOIN x". I think we want a real
clear syntactical separation between the deletion target table and the
other tables.

Also we do have the precedent of the way that UPDATE does things. We
don't want to use the keyword FROM because of confusion, but I think
we want to keep it basically the same as UPDATE.

regards, tom lane


From: Harald Fuchs <hf0722x(at)protecting(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-10 12:01:00
Message-ID: pu3c2v2oeb.fsf@srv.protecting.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

In article <16580(dot)1092071243(at)sss(dot)pgh(dot)pa(dot)us>,
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:

> Jan Wieck <JanWieck(at)Yahoo(dot)com> writes:
>> What about
>> DELETE FROM staff JOIN users ...
>> then?

> I don't much care for that, mainly because in my mind "x JOIN y" should
> always be semantically equivalent to "y JOIN x". I think we want a real
> clear syntactical separation between the deletion target table and the
> other tables.

Just one minor nit:

You're talking about "the deletion target table". Sorry to mention
the M word again, but MySQL allows deleting from more than one table
at the same time. Should we support that?


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: hf0722x(at)protecting(dot)net
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-10 14:28:41
Message-ID: 28144.1092148121@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Harald Fuchs <hf0722x(at)protecting(dot)net> writes:
> You're talking about "the deletion target table". Sorry to mention
> the M word again, but MySQL allows deleting from more than one table
> at the same time. Should we support that?

There is zero interest in that around here, AFAIK. I don't think it's
even very well-defined...

regards, tom lane


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Jan Wieck <JanWieck(at)Yahoo(dot)com>, Josh Berkus <josh(at)agliodbs(dot)com>, Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-10 14:31:45
Message-ID: 200408101431.i7AEVj410526@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


I have added the USING mention to the TODO list description for the
item.

* Allow DELETE to handle table aliases for self-joins [delete]

There is no way to specify a table alias for the deleted table in
the DELETE WHERE clause because there is no FROM clause. The agreed
approach is to allow a USING clause to specify additional tables
with aliases. UPDATE already has such an optional FROM clause.

---------------------------------------------------------------------------

=Tom Lane wrote:
> Jan Wieck <JanWieck(at)Yahoo(dot)com> writes:
> > What about
> > DELETE FROM staff JOIN users ...
> > then?
>
> I don't much care for that, mainly because in my mind "x JOIN y" should
> always be semantically equivalent to "y JOIN x". I think we want a real
> clear syntactical separation between the deletion target table and the
> other tables.
>
> Also we do have the precedent of the way that UPDATE does things. We
> don't want to use the keyword FROM because of confusion, but I think
> we want to keep it basically the same as UPDATE.
>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faqs/FAQ.html
>

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073


From: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>
To: hf0722x(at)protecting(dot)net
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-10 14:37:05
Message-ID: 4118DD91.6070300@familyhealth.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

> You're talking about "the deletion target table". Sorry to mention
> the M word again, but MySQL allows deleting from more than one table
> at the same time. Should we support that?

No, because it makes no logical sense at all...

Chris


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Jan Wieck <JanWieck(at)Yahoo(dot)com>, Josh Berkus <josh(at)agliodbs(dot)com>, Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-10 14:40:48
Message-ID: 28283.1092148848@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> There is no way to specify a table alias for the deleted table in
> the DELETE WHERE clause because there is no FROM clause.

This description confuses two quite separate issues.

regards, tom lane


From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Harald Fuchs <hf0722x(at)protecting(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-10 14:43:49
Message-ID: 20040810072859.G73605@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


On Tue, 10 Aug 2004, Harald Fuchs wrote:

> In article <16580(dot)1092071243(at)sss(dot)pgh(dot)pa(dot)us>,
> Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
>
> > Jan Wieck <JanWieck(at)Yahoo(dot)com> writes:
> >> What about
> >> DELETE FROM staff JOIN users ...
> >> then?
>
> > I don't much care for that, mainly because in my mind "x JOIN y" should
> > always be semantically equivalent to "y JOIN x". I think we want a real
> > clear syntactical separation between the deletion target table and the
> > other tables.
>
> Just one minor nit:
>
> You're talking about "the deletion target table". Sorry to mention
> the M word again, but MySQL allows deleting from more than one table
> at the same time. Should we support that?

I don't think we should unless we can give a good definition to its
behavior. The message (on -sql?) on UPDATE...FROM doing not what the user
expected when the join wasn't 1-1 gives a good example of some of the
issues that come from these sorts of extensions.

I don't see anything in the MySQL delete syntax docs that talks about what
happens in that case. If you do:

delete from foo, bar where bar.val=3;

Is that an error, is it only an error if one of foo or bar has more than
1 row? In the case both have more than 1 row, does it delete all rows in
foo or none or something else?


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Jan Wieck <JanWieck(at)Yahoo(dot)com>, Josh Berkus <josh(at)agliodbs(dot)com>, Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-10 15:00:26
Message-ID: 200408101500.i7AF0Qq15552@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> > There is no way to specify a table alias for the deleted table in
> > the DELETE WHERE clause because there is no FROM clause.
>
> This description confuses two quite separate issues.

Yea, it does.

How is this text:

* Allow DELETE to handle table aliases for self-joins

There is no way to create a table alias for the deleted table for use
in the DELETE WHERE clause. The agreed approach is to allow a USING
clause to specify additional tables. UPDATE already has an optional
FROM clause for this purpose.

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Jan Wieck <JanWieck(at)Yahoo(dot)com>, Josh Berkus <josh(at)agliodbs(dot)com>, Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-10 17:01:42
Message-ID: 29397.1092157302@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> Tom Lane wrote:
>> This description confuses two quite separate issues.

> Yea, it does.

> How is this text:

> * Allow DELETE to handle table aliases for self-joins

> There is no way to create a table alias for the deleted table for use
> in the DELETE WHERE clause. The agreed approach is to allow a USING
> clause to specify additional tables. UPDATE already has an optional
> FROM clause for this purpose.

Not a lot better. They really should be two separate issues, because we
could in theory do either without the other.

* Allow an alias to be provided for the target table in UPDATE/DELETE

This is not SQL-spec but many DBMSs allow it.

* Allow additional tables to be specified in DELETE for joining

UPDATE already allows this (UPDATE...FROM) and we need a similar
ability in DELETE. It's been agreed that the keyword should be
USING, to avoid anything so confusing as DELETE FROM a FROM b.

I have not looked to see whether or not there are already entries
similar to these.

regards, tom lane


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Jan Wieck <JanWieck(at)Yahoo(dot)com>, Josh Berkus <josh(at)agliodbs(dot)com>, Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-10 17:09:09
Message-ID: 200408101709.i7AH99b09457@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> > Tom Lane wrote:
> >> This description confuses two quite separate issues.
>
> > Yea, it does.
>
> > How is this text:
>
> > * Allow DELETE to handle table aliases for self-joins
>
> > There is no way to create a table alias for the deleted table for use
> > in the DELETE WHERE clause. The agreed approach is to allow a USING
> > clause to specify additional tables. UPDATE already has an optional
> > FROM clause for this purpose.
>
> Not a lot better. They really should be two separate issues, because we
> could in theory do either without the other.
>
> * Allow an alias to be provided for the target table in UPDATE/DELETE
>
> This is not SQL-spec but many DBMSs allow it.

I don't think we would ever do the above item. I see no purpose to
allowing the UPDATE/DELETE table to have an alias as long as you can
create another reference to the table that does have an alias. In fact,
having a alias for the deleted item seems too prone to confusion.

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Jan Wieck <JanWieck(at)Yahoo(dot)com>, Josh Berkus <josh(at)agliodbs(dot)com>, Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-10 17:16:58
Message-ID: 29527.1092158218@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> Tom Lane wrote:
>> * Allow an alias to be provided for the target table in UPDATE/DELETE
>>
>> This is not SQL-spec but many DBMSs allow it.

> I don't think we would ever do the above item.

Why not? You can hardly argue that "it's not SQL spec" while
simultaneously putting in a much larger extension to the spec.

> I see no purpose to
> allowing the UPDATE/DELETE table to have an alias

Brevity. If you are really updating AVeryLongSchemaName.AVeryLongTableName
then you would reasonably want to have an alias for that. In the pure
SQL-spec syntax it's not so important because there's seldom a need to
name the table again within the query. But in a self-join situation you
would be forced to name the target table within the query, and then a
shorter alias would be both easier to type and less prone to confusion.
(Even in pure SQL, you may need to name the table again for references
within subqueries that have duplicate column names.)

regards, tom lane


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Jan Wieck <JanWieck(at)Yahoo(dot)com>, Josh Berkus <josh(at)agliodbs(dot)com>, Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-10 17:23:20
Message-ID: 200408101723.i7AHNKx11852@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> > Tom Lane wrote:
> >> * Allow an alias to be provided for the target table in UPDATE/DELETE
> >>
> >> This is not SQL-spec but many DBMSs allow it.
>
> > I don't think we would ever do the above item.
>
> Why not? You can hardly argue that "it's not SQL spec" while
> simultaneously putting in a much larger extension to the spec.
>
> > I see no purpose to
> > allowing the UPDATE/DELETE table to have an alias
>
> Brevity. If you are really updating AVeryLongSchemaName.AVeryLongTableName
> then you would reasonably want to have an alias for that. In the pure
> SQL-spec syntax it's not so important because there's seldom a need to
> name the table again within the query. But in a self-join situation you
> would be forced to name the target table within the query, and then a
> shorter alias would be both easier to type and less prone to confusion.
> (Even in pure SQL, you may need to name the table again for references
> within subqueries that have duplicate column names.)

Yea, I guess for a long table that also needed an alias you would have
to specify the long name every time you reference the table. However,
we haven't had anyone ask for that capability, even for UPDATE which
does already have that limitation. Seems like a new TODO item but I am
not sure anyone wants it.

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Jan Wieck <JanWieck(at)Yahoo(dot)com>, Josh Berkus <josh(at)agliodbs(dot)com>, Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-10 17:25:18
Message-ID: 29596.1092158718@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
>>> * Allow an alias to be provided for the target table in UPDATE/DELETE

> Yea, I guess for a long table that also needed an alias you would have
> to specify the long name every time you reference the table. However,
> we haven't had anyone ask for that capability,

Yes we have. Do I need to trawl the archives for you? It's been asked
for quite a few times.

regards, tom lane


From: Josh Berkus <josh(at)agliodbs(dot)com>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-10 17:26:12
Message-ID: 200408101026.12982.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce,

> Yea, I guess for a long table that also needed an alias you would have
> to specify the long name every time you reference the table. However,
> we haven't had anyone ask for that capability, even for UPDATE which
> does already have that limitation. Seems like a new TODO item but I am
> not sure anyone wants it.

Oh, I think many people want this (I'd use it) but it's not in anybody's "top
10" list which is why you don't hear about it. I'd say throw it in the TODO
in case some university student studying query parsers wants to implement it
for us at some undefined date in the future. Also, it will spare you
questions about it later ... "It's in the TODO!"

--
Josh Berkus
Aglio Database Solutions
San Francisco


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Jan Wieck <JanWieck(at)Yahoo(dot)com>, Josh Berkus <josh(at)agliodbs(dot)com>, Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-10 17:52:06
Message-ID: 200408101752.i7AHq6817045@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> >>> * Allow an alias to be provided for the target table in UPDATE/DELETE
>
> > Yea, I guess for a long table that also needed an alias you would have
> > to specify the long name every time you reference the table. However,
> > we haven't had anyone ask for that capability,
>
> Yes we have. Do I need to trawl the archives for you? It's been asked
> for quite a few times.

OK, TODO updated:

* Allow an alias to be provided for the target table in UPDATE/DELETE

This is not SQL-spec but many DBMSs allow it.

* Allow additional tables to be specified in DELETE for joins

UPDATE already allows this (UPDATE...FROM) but we need similar
functionality in DELETE. It's been agreed that the keyword should
be USING, to avoid anything as confusing as DELETE FROM a FROM b.

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073


From: Josh Berkus <josh(at)agliodbs(dot)com>
To: Andreas Pflug <pgadmin(at)pse-consulting(dot)de>, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Jan Wieck <JanWieck(at)Yahoo(dot)com>, Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-10 23:03:38
Message-ID: 200408101603.38503.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andreas,

> The USING would be in place of the mandatory FROM in MSSQL. And why use
> a different keyword for the same thing in DELETE and UPDATE?

Um, because for us the 1st FROM isn't optional (per SQL spec)?

--
-Josh Berkus
"A developer of Very Little Brain"
Aglio Database Solutions
San Francisco


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andreas Pflug <pgadmin(at)pse-consulting(dot)de>
Cc: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, Jan Wieck <JanWieck(at)Yahoo(dot)com>, Josh Berkus <josh(at)agliodbs(dot)com>, Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-10 23:06:31
Message-ID: 13712.1092179191@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andreas Pflug <pgadmin(at)pse-consulting(dot)de> writes:
> The USING would be in place of the mandatory FROM in MSSQL. And why use
> a different keyword for the same thing in DELETE and UPDATE?

Please read the earlier part of the thread... this ground was covered
already.

As for emulating MSSQL's syntax, we are *not* about to emulate their
semantics, so it seems a good idea not to use the same syntax.

regards, tom lane


From: Andreas Pflug <pgadmin(at)pse-consulting(dot)de>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Jan Wieck <JanWieck(at)Yahoo(dot)com>, Josh Berkus <josh(at)agliodbs(dot)com>, Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-11 00:58:02
Message-ID: 41196F1A.2010503@pse-consulting.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian wrote:
It's been agreed that the keyword should
> be USING, to avoid anything as confusing as DELETE FROM a FROM b.

FYI,

MSSQL says

DELETE
[FROM]
{tablename}
[FROM {<tablesource> [, ...] ]
[WHERE <condition>]

Note that the first FROM is optional (as in Oracle), we can have

DELETE a FROM b

The USING would be in place of the mandatory FROM in MSSQL. And why use
a different keyword for the same thing in DELETE and UPDATE?

DELETE a FROM b
UPDATE a FROM b
DELETE FROM a USING b

Regards,
Andreas


From: Andreas Pflug <pgadmin(at)pse-consulting(dot)de>
To: josh(at)agliodbs(dot)com
Cc: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Jan Wieck <JanWieck(at)Yahoo(dot)com>, Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add Missing From?
Date: 2004-08-11 10:28:17
Message-ID: 4119F4C1.40302@pse-consulting.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Josh Berkus wrote:
> Andreas,
>
>
>>The USING would be in place of the mandatory FROM in MSSQL. And why use
>>a different keyword for the same thing in DELETE and UPDATE?
>
>
> Um, because for us the 1st FROM isn't optional (per SQL spec)?
>

Seems that many RDBMS regard that FROM as a noise word. Making it
optional would probably enhance portability, I can't see drawbacks.

Regards,
Andreas