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


Sun, 8 Aug 2004 16:26:49 -0700
Josh Berkus <josh@agliodbs.com>
Add Missing From?
Josh Berkus <josh@agliodbs.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

Sun, 08 Aug 2004 20:46:45 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: Add Missing From? 
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

Sun, 8 Aug 2004 18:44:32 -0700
Josh Berkus <josh@agliodbs.com>
Re: Add Missing From?
Josh Berkus <josh@agliodbs.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

Sun, 08 Aug 2004 22:32:38 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: Add Missing From? 
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

Sun, 8 Aug 2004 22:32:52 -0400
Robert Treat <xzilla@users.sourceforge.net>
Re: Add Missing From?
Robert Treat <xzilla@users.sourceforge.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

Sun, 08 Aug 2004 22:36:21 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: Add Missing From? 
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

Sun, 8 Aug 2004 19:48:23 -0700
Josh Berkus <josh@agliodbs.com>
Re: Add Missing From?
Josh Berkus <josh@agliodbs.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

Sun, 08 Aug 2004 23:16:02 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: Add Missing From? 
Tom Lane wrote:
> Josh Berkus <josh@agliodbs.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@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Sun, 8 Aug 2004 23:31:58 -0400 (EDT)
Bruce Momjian <pgman@candle.pha.pa.us>
Re: Add Missing From?
On Sunday 08 August 2004 23:16, Tom Lane wrote:
> Josh Berkus <josh@agliodbs.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

Mon, 9 Aug 2004 00:12:41 -0400
Robert Treat <xzilla@users.sourceforge.net>
Re: Add Missing From?
Robert Treat <xzilla@users.sourceforge.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

Mon, 09 Aug 2004 00:29:01 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: Add Missing From? 
> 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




Mon, 09 Aug 2004 12:57:53 +0800
Christopher Kings-Lynne <chriskl@familyhealth.com.au>
Re: Add Missing From?
In article <5431.1092025741@sss.pgh.pa.us>,
Tom Lane <tgl@sss.pgh.pa.us> writes:

> Robert Treat <xzilla@users.sourceforge.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)


09 Aug 2004 13:08:14 +0200
Harald Fuchs <hf0722x@protecting.net>
Re: Add Missing From?
On 8/9/2004 12:29 AM, Tom Lane wrote:

> Robert Treat <xzilla@users.sourceforge.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@Yahoo.com #

Mon, 09 Aug 2004 10:53:05 -0400
Jan Wieck <JanWieck@Yahoo.com>
Re: Add Missing From?
Harald Fuchs <hf0722x@protecting.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

Mon, 09 Aug 2004 10:54:54 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: Add Missing From? 
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

Mon, 9 Aug 2004 09:53:29 -0700
Josh Berkus <josh@agliodbs.com>
Re: Add Missing From?
Josh Berkus <josh@agliodbs.com> writes:
> Oh, and MySQL's "multi-table deletes":  PLEASE tell me that's not 
> SQL-standard.

It's not.

			regards, tom lane

Mon, 09 Aug 2004 13:00:33 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: Add Missing From? 
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@Yahoo.com #

Mon, 09 Aug 2004 13:02:02 -0400
Jan Wieck <JanWieck@Yahoo.com>
Re: Add Missing From?
Jan Wieck <JanWieck@Yahoo.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

Mon, 09 Aug 2004 13:07:23 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: Add Missing From? 
In article <16580.1092071243@sss.pgh.pa.us>,
Tom Lane <tgl@sss.pgh.pa.us> writes:

> Jan Wieck <JanWieck@Yahoo.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?


10 Aug 2004 14:01:00 +0200
Harald Fuchs <hf0722x@protecting.net>
Re: Add Missing From?
Harald Fuchs <hf0722x@protecting.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

Tue, 10 Aug 2004 10:28:41 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: Add Missing From? 

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@Yahoo.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@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Tue, 10 Aug 2004 10:31:45 -0400 (EDT)
Bruce Momjian <pgman@candle.pha.pa.us>
Re: Add Missing From?
> 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


Tue, 10 Aug 2004 22:37:05 +0800
Christopher Kings-Lynne <chriskl@familyhealth.com.au>
Re: Add Missing From?
Bruce Momjian <pgman@candle.pha.pa.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

Tue, 10 Aug 2004 10:40:48 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: Add Missing From? 

On Tue, 10 Aug 2004, Harald Fuchs wrote:

> In article <16580.1092071243@sss.pgh.pa.us>,
> Tom Lane <tgl@sss.pgh.pa.us> writes:
>
> > Jan Wieck <JanWieck@Yahoo.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?

Tue, 10 Aug 2004 07:43:49 -0700 (PDT)
Stephan Szabo <sszabo@megazone.bigpanda.com>
Re: Add Missing From?
Tom Lane wrote:
> Bruce Momjian <pgman@candle.pha.pa.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@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Tue, 10 Aug 2004 11:00:26 -0400 (EDT)
Bruce Momjian <pgman@candle.pha.pa.us>
Re: Add Missing From?
Bruce Momjian <pgman@candle.pha.pa.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

Tue, 10 Aug 2004 13:01:42 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: Add Missing From? 
Tom Lane wrote:
> Bruce Momjian <pgman@candle.pha.pa.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@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Tue, 10 Aug 2004 13:09:09 -0400 (EDT)
Bruce Momjian <pgman@candle.pha.pa.us>
Re: Add Missing From?
Bruce Momjian <pgman@candle.pha.pa.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

Tue, 10 Aug 2004 13:16:58 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: Add Missing From? 
Tom Lane wrote:
> Bruce Momjian <pgman@candle.pha.pa.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@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Tue, 10 Aug 2004 13:23:20 -0400 (EDT)
Bruce Momjian <pgman@candle.pha.pa.us>
Re: Add Missing From?
Bruce Momjian <pgman@candle.pha.pa.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

Tue, 10 Aug 2004 13:25:18 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: Add Missing From? 
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

Tue, 10 Aug 2004 10:26:12 -0700
Josh Berkus <josh@agliodbs.com>
Re: Add Missing From?
Tom Lane wrote:
> Bruce Momjian <pgman@candle.pha.pa.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@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Tue, 10 Aug 2004 13:52:06 -0400 (EDT)
Bruce Momjian <pgman@candle.pha.pa.us>
Re: Add Missing From?
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


Tue, 10 Aug 2004 16:03:38 -0700
Josh Berkus <josh@agliodbs.com>
Re: Add Missing From?
Andreas Pflug <pgadmin@pse-consulting.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

Tue, 10 Aug 2004 19:06:31 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: Add Missing From? 
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

Wed, 11 Aug 2004 00:58:02 +0000
Andreas Pflug <pgadmin@pse-consulting.de>
Re: Add Missing From?
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



Wed, 11 Aug 2004 10:28:17 +0000
Andreas Pflug <pgadmin@pse-consulting.de>
Re: Add Missing From?