Re: ambiguous
От | Brett W. McCoy |
---|---|
Тема | Re: ambiguous |
Дата | |
Msg-id | Pine.LNX.4.30.0103071058020.14637-100000@chapelperilous.net обсуждение исходный текст |
Ответ на | ambiguous (si <s@remail.net>) |
Список | pgsql-general |
On Wed, 7 Mar 2001, si wrote: > If I assign the same name to 2 columns in 2 different tables: > > +--------------------------------------+ > | DEPARTMENT | > +----------+----------------+----------+ > | LOCATION | DESCRIPTION | DEPT_NO | > +----------+----------------+----------+ > | Bedrock | Administration | 1 | > +----------+----------------+----------+ > > +--------------------------------+ > | EMPLOYEE | > +---------+------------+---------+ > | EMPL_ID | NAME_LAST | DEPT_NO | > +---------+------------+---------+ > | 1 | Slate | 1 | > +---------+------------+---------+ > > select * from DEPARTMENT, Employee where dept_no = '1'; > > PG throws up: > ERROR: Column 'dept_no' is ambiguous > > Is this not allowed? or is my sql understanding wrong? It's correct behavior, because it can't differentiate between the two fields with the same name. But this shouldn't present a problem if you are using dept_no as a join field. You will want to select things this way: select d.*, e.empl_no, d.name_last from DEPARTMENT d, Employee e where e.dept_no = d.dept_no and d.dept_no = 1; It's longer SQL, but it's also more precise. -- Brett http://www.chapelperilous.net/~bmccoy/ ------------------------------------------------------------------------ A bird in the hand is worth what it will bring.
В списке pgsql-general по дате отправления: