Deleting Multiple Rows Based on Multiple Columns

Поиск
Список
Период
Сортировка
От Rich Shepard
Тема Deleting Multiple Rows Based on Multiple Columns
Дата
Msg-id alpine.LNX.2.00.1108131128490.1426@salmo.appl-ecosys.com
обсуждение исходный текст
Ответы Re: Deleting Multiple Rows Based on Multiple Columns  (David Johnston <polobo@yahoo.com>)
Список pgsql-general
   Thanks to David J. I have a working script to locate multiple rows having
the same values in three candidate columns. I used an enhanced version of
this script to copy those duplicate (and triplicate) records to a clone of
the original table.

   Now I would like to delete those duplicates from the original table in
either of two ways, but my Google searches have not produced hits where the
selection criteria for the DELETE has multiple columns.

   If it is possible to leave one row with specific values in the columns
(loc_name, sample_date, param) and delete the additional ones, I'd like to
learn how to do so. I know that I'll have use for these techniques with
future data.

   Else, I'd like to delete all those rows with multiple copies. Then I'll
manually remove the extra rows in emacs, and insert the remainder in the
original table.

   The script I tried to to the latter is:

DELETE FROM chemistry
   WHERE
   (SELECT lab_nbr, loc_name, sample_date, param, quant, units, qa_qc,
        easting, northing, remark
        FROM chemistry
        Natural Inner join (
        SELECT loc_name, sample_date, param, Count(*) as duplicate_count
          FROM chemistry
          GROUP BY loc_name, sample_date, param) grouped
        WHERE duplicate_count > 1);

   But postgres wants a single column in the first SELECT.

TIA,

Rich

В списке pgsql-general по дате отправления:

Предыдущее
От: Pavel Stehule
Дата:
Сообщение: Re: Functions returning setof record -- can I use a table type as my return type hint?
Следующее
От: c k
Дата:
Сообщение: Re: [ADMIN] Using Postgresql as application server