Re: is there a distinct function for comma lists ?

From: Andreas Gaab <A(dot)Gaab(at)scanlab(dot)de>
To: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: is there a distinct function for comma lists ?
Date: 2010-09-07 12:19:19
Message-ID: 48DA836F3865C54B8FBF424A3B775AF6011D0A5EC1@Exchange-Server
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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(at)postgresql(dot)org [mailto:pgsql-sql-owner(at)postgresql(dot)org] Im Auftrag von Andreas
Gesendet: Dienstag, 7. September 2010 13:52
An: pgsql-sql(at)postgresql(dot)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?

--
Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Bryce Nesbitt 2010-09-07 19:15:21 Sequential scan evaluating function for each row, seemingly needlessly
Previous Message Andreas 2010-09-07 11:52:19 is there a distinct function for comma lists ?