Re: transfer data - Mailing list pgsql-general

From Dennis Gearon
Subject Re: transfer data
Date
Msg-id 3E9308FB.4080700@cvc.net
Whole thread Raw
In response to transfer data  (Detlef Jockheck <detlef@jockheck.de>)
List 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
>


pgsql-general by date:

Previous
From: Detlef Jockheck
Date:
Subject: transfer data
Next
From: P G
Date:
Subject: How does PostgreSQL treat null values in unique composite constraints???