Is this a bug? - Mailing list pgsql-sql

From Jack Gao
Subject Is this a bug?
Date
Msg-id 9sqakt$op1$1@news.tht.net
Whole thread Raw
List pgsql-sql
Hi, There

When I use Update with Join, I got some problem.

I have a table as user config table (tblUserConfig), and another table as
config item table (tblConfigItem).

CREATE TABLE tblUserConfig (ID              integer NOT NULL DEFAULT nextval('tblUserConfig_pKey_ID')
PRIMARY KEY,UserID          integer NOT NULL,                         -- tblUserItemID          integer NOT NULL,
                 -- tblConfigItemValue           varchar(1024)
 
);


CREATE TABLE tblConfigItem (ID              integer NOT NULL DEFAULT nextval('tblConfigItem_pKey_ID')
PRIMARY KEY,Scope           integer NOT NULL DEFAULT 1,               -- 1: System
config, 2: Section config, 3: User configName            varchar(64) NOT NULL,Description     varchar(64),DataType
 integer NOT NULL DEFAULT 1,               -- 1: String, 2:
 
Numeric, 3: Boolean, 4: DateTimeDefaultValue    varchar(1024)
);

Now, I would like to update tblUserConfig to set Value of 'UserClassID' to,
for example '1'. So I write a sql string like this:

Update tblUserConfig Set Value = '1' From tblUserConfig As a Join
tblConfigItem As b On a.ItemID = b.ID And b.Scope = 3 Where a.UserID = 1 And
b.Name = 'UserClassID';

It always update all records in tblUserConfig table!!!

If I change it to:
Update tblUserConfig Set Value = '1' Where UserID = 1 And ItemID = (Select
ID From tblConfigItem Where Scope = 3 And Name = 'UserClassID');

It works fine.

So, is this a bug? or I make anything wrong?

Thanks

Noodle




pgsql-sql by date:

Previous
From: "Llew Goodstadt"
Date:
Subject: Re: how do I update or insert efficently in postgres
Next
From: Martín Marqués
Date:
Subject: Re: Unable to use '-' in column names in PLPGSQL