Re: can these queries be combined into one?

From: Tom Molesworth <tom(at)audioboundary(dot)com>
To: hamann(dot)w(at)t-online(dot)de
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: can these queries be combined into one?
Date: 2012-03-26 12:38:38
Message-ID: 4F70634E.7020502@audioboundary.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

On 25/03/12 08:16, hamann(dot)w(at)t-online(dot)de wrote:
> I am currently doing something like
>
> select ordercode, descr, codes into temp table x from products where ...
> Here codes is a bit-mapped field
> update x set codes = codes | 512 from othertable t where ordercode = t.ordercode and ....
> select * from x
>
> Is there a way to avoid that temp table?

You just want to map some of the values in the codes field to different
values? If so, case/when should help, something like:

select ordercode, descr, case when ordercode = t.ordercode and .... then
codes | 512 else codes end as "codes" from products where ...

Note this is a read-only operation - some of the other answers seemed to
be updating the base tables, although maybe that's what you wanted?

cheers,

Tom

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Greg Sabino Mullane 2012-03-26 13:05:51 Re: compilation info without pg_config
Previous Message Martín Marqués 2012-03-26 11:41:46 PostgreSQL crashed server