INSERT ... SELECT DISTINCT - Doesn't work...
От | Cesar A. K. Grossmann |
---|---|
Тема | INSERT ... SELECT DISTINCT - Doesn't work... |
Дата | |
Msg-id | 396B7FAB.2DA71679@rotnet.com.br обсуждение исходный текст |
Список | pgsql-general |
Hi I'm trying to normalize a database, and want to derivate one relation from another. The original relation is like: user_operations ( user_id integer, user_name varchar, user_operation varchar) It stores the 'user_operation' item, and also works as a user database (or some like this...). To get the different users from the database, I have this query: SELECT DISTINCT user_id, user_name FROM user_operations; I need to do some normalization works here, and want to insert data from user_operations in the new 'users' relation: CREATE TABLE users ( user_id integer, user_name varchar); To inser the data, I have tried the straight: INSERT INTO users (user_id, user_name) SELECT DISTINCT user_id, user_name FROM user_operations; But it doesn't work as I expect. Suppose there are 15000 rows at user_operations, but only 50 different (user_id, user_name). The SELECT DISTINCT returns only 50 rows, but the INSERT ... SELECT DISTINCT inserts 15000 rows! I think the DISTINCT clause, when used in a INSERT INTO ... SELECT doesn't have any effect... Is it a bug? Can anybody help me figure out how to get only the different (user_id, user_name) from user_operations, without any repeat? TIA -- César A. K. Grossmann ckant@usa.net http://members.xoom.com/ckant/ http://www.halcyon.com/sciclub/cgi-pvt/instr/instr.html
В списке pgsql-general по дате отправления: