Re: transfer data

From: Dennis Gearon <gearond(at)cvc(dot)net>
To: Detlef Jockheck <detlef(at)jockheck(dot)de>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: transfer data
Date: 2003-04-08 17:38:03
Message-ID: 3E9308FB.4080700@cvc.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

nope, update and insert are it.

OR, you could put it all in one table with an additional column that had
status's like 'A', and 'B', and have a unique index on (article_number, status),
but it would still involve inserts and updates. How else is data changed?

You could abstract it by writing a PL/PGSQL function that was named something
like change_status_of_articles( article_number, old_status, new_status), and
that would make life easier AFTER you wrote the function. BUT, the function
would have all the same things in it that you've been writing by hand; You just
wouldn't have to do anything but run the function after that.

Detlef Jockheck wrote:
> Hi!
>
> I have two tables:
>
> Table A:
> article_number, count
> a 2
> b 5
> g 3
>
> Table B:
> article_number, count
> b 7
>
> Now I want to transfer 2 units of b and 3 units of g from Table A to table
> B. So the result should be:
>
> Table A:
> article_number, count
> a 2
> b 3
> g 0 (or empty line)
>
> Table B:
> article_number, count
> b 9
> g 3
>
> What is the best way to do this transaction with postgresql? I've tried to do
> this with update and insert statements from psql but I'm sure there is a
> better way!?
>
> ciao
> Detlef
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message P G 2003-04-08 18:12:35 How does PostgreSQL treat null values in unique composite constraints???
Previous Message Detlef Jockheck 2003-04-08 17:17:24 transfer data