Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 0F3F61337B65 for ; Tue, 28 Sep 2010 11:08:09 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 86598-09 for ; Tue, 28 Sep 2010 14:08:01 +0000 (UTC) X-Greylist: delayed 00:07:13.481911 by SQLgrey-1.7.6 Received: from forward13.mail.yandex.net (forward13.mail.yandex.net [95.108.130.120]) by mail.postgresql.org (Postfix) with ESMTP id 765F81337B64 for ; Tue, 28 Sep 2010 11:08:01 -0300 (ADT) Received: from web147.yandex.ru (web147.yandex.ru [95.108.131.162]) by forward13.mail.yandex.net (Yandex) with ESMTP id 17990108130C; Tue, 28 Sep 2010 18:00:46 +0400 (MSD) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1285682446; bh=A9awbwKclELiWEi9KVn5nKEYEey0K+qhBNJF/WhK/I4=; h=From:To:In-Reply-To:References:Subject:MIME-Version:Message-Id: Date:Content-Transfer-Encoding:Content-Type; b=DrZOfs6C6FDCzxLo6FkF0OQw0Wzoae0WQBgMAk/MuP+Qn5k2Vx94EqjZk35cSaA5s CdIfzH++DQD+Hwkl+JMo/cfXN8z+i3B/4wMPjM+J44OYVLoapl98HRcXX0xbcSbHt+ W8Utbit6BvZmDNyMkw7hltXZLkDR1uqE2350Dc7M= Received: from localhost (localhost.localdomain [127.0.0.1]) by web147.yandex.ru (Yandex) with ESMTP id 0DF046E70064; Tue, 28 Sep 2010 18:00:46 +0400 (MSD) X-Yandex-Spam: 0 X-Yandex-Front: web147.yandex.ru X-Yandex-TimeMark: 1285682446 Received: from user-18.81.118.217.in-addr.arpa (user-18.81.118.217.in-addr.arpa [217.118.81.18]) by mail.yandex.ru with HTTP; Tue, 28 Sep 2010 18:00:45 +0400 From: msi77 To: Andreas Gaab ,pgsql-sql@postgresql.org In-Reply-To: <48DA836F3865C54B8FBF424A3B775AF6011D0A5EC1@Exchange-Server> References: <4C862773.2070900@gmx.net> <48DA836F3865C54B8FBF424A3B775AF6011D0A5EC1@Exchange-Server> Subject: Re: is there a distinct function for comma lists ? MIME-Version: 1.0 Message-Id: <445681285682445@web147.yandex.ru> Date: Tue, 28 Sep 2010 18:00:45 +0400 X-Mailer: Yamail [ http://yandex.ru ] 5.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=utf-8 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=2.917 tagged_above=-5 required=5 tests=BAYES_50=0.8, RCVD_IN_BL_SPAMCOP_NET=1.347, RCVD_IN_SORBS_WEB=0.77 X-Spam-Level: ** X-Archive-Number: 201009/110 X-Sequence-Number: 34641 Hi, > And as bonus ... is there a way to find IDs that are in the list but not > in the table without creating a temporary table and use a join? Does below satisfy you? select * from (values (1), (2), (3), (5), (7), (11), (3), (6), (13), (13), (3), (11)) as X(a) where a not in(select id from mytable) Serge http://www.sql-ex.com/ > Hi, > For the problem 1 perhaps something like > select distinct unnest(ARRAY[ 1, 2, 3, 5, 7, 11, 3, 6, 13, 13, 3, 11 ]) > Regards, > Andreas > -----Ursprüngliche Nachricht----- > Von: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] Im Auftrag von Andreas > Gesendet: Dienstag, 7. September 2010 13:52 > An: pgsql-sql@postgresql.org > Betreff: [SQL] is there a distinct function for comma lists ? > Hi, > is there a distinct function for comma separated lists ? > I sometimes need to update tables where I got a set of IDs, like: > update mytable > set someattribute = 42 > where mytable.id in > ( 1, 2, 3, 5, 7, 11, 3, 6, 13, 13, 3, 11 ... ) > So there are double entries in the list but in this case its just > overhead but no problem. > But for calculated values this would not allways be desirable. > update mytable > set someattribute = someattribute + 1 > where mytable.id in > ( 1, 2, 3, 5, 7, 11, 3, 6, 13, 13, 3, 11 ... ) > How could I get a distinct list? Those lists can have 2000-3000 IDs > sometimes. > One solution was as follows but perhaps there is something more elegant? > update mytable > set someattribute = someattribute + 1 > where mytable.id in > ( select distinct id from mytable where id in ( 1, 2, 3, 5, 7, 11, 3, > 6, 13, 13, 3, 11 ... ) ) > And as bonus ... is there a way to find IDs that are in the list but not > in the table without creating a temporary table and use a join? > Здесь спама нет http://mail.yandex.ru/nospam/sign