pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gary Stainburn <gary.stainburn@ringways.co.uk>
To: 'pgsql-sql@postgresql.org' <pgsql-sql@postgresql.org>
Subject: Re: best way to swap two records (computer details)
Date: Wed, 23 Mar 2005 23:25:14 +0000
Message-ID: <200503232325.14799.gary.stainburn@ringways.co.uk> (raw)
In-Reply-To: <200503231726.06583.gary.stainburn@ringways.co.uk>
References: <200503181325.23293.gary.stainburn@ringways.co.uk>
	<op.snumxjkpth1vuj@localhost>
	<200503231726.06583.gary.stainburn@ringways.co.uk>

On Wednesday 23 March 2005 5:26 pm, you wrote:
> On Friday 18 March 2005 7:54 pm, you wrote:
> > > My question is what's the best way to swap settings between the
> > > two computer records and swap any software installed?  Ideally
> > > I'd like it in the form of a function where I can pass the two
> > > p_id's and return a boolean reflecting success (true) or fail
> > > (false).
> >
> > 	I'd say something like that (generic table names) :
> >
> > If you're confident :
> > UPDATE stuff SET owner = (CASE IF owner='A' THEN 'B' ELSE 'A' END)
> > WHERE owner IN ('A','B')
> >
> > If you're paranoid :
> > UPDATE stuff SET owner = (CASE IF owner='A' THEN 'B' ELSE IF
> > owner='B' THEN 'A' ELSE owner END) WHERE owner IN ('A','B')
>
> Hello again.
>
> I've tried the first one but get a syntax error. Anyone see why?
>
> hardware=# update pieces set p_owner = (case if p_owner = 305 then
> 724 else 305 end) where p_owner in (305, 724);
> ERROR:  parser: parse error at or near "p_owner"
> hardware=#

Sorted it.  The 'IF' should be 'WHEN'
-- 
Gary Stainburn
 
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000     




view thread (7+ messages)

Message-ID: <200503232325.14799.gary.stainburn@ringways.co.uk>
Permalink:  ../200503232325.14799.gary.stainburn@ringways.co.uk/
Also on:    postgresql.org/message-id/200503232325.14799.gary.stainburn@ringways.co.uk

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: gary.stainburn@ringways.co.uk
  Subject: Re: best way to swap two records (computer details)
  In-Reply-To: <200503232325.14799.gary.stainburn@ringways.co.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox