Received: from ns.dsn.ro ([217.156.107.1]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f4HEU9A00659 for ; Thu, 17 May 2001 10:30:09 -0400 (EDT) (envelope-from george@dsn.ro) Received: from dsn.ro (IDENT:george@george.dsn.ro [217.156.107.12]) by ns.dsn.ro (8.10.2/8.10.2) with ESMTP id f4HEOnH13490; Thu, 17 May 2001 17:24:49 +0300 Message-ID: <3B03DFF4.FB6BAF6E@dsn.ro> Date: Thu, 17 May 2001 17:28:04 +0300 From: George Moga Organization: DataSystems Srl Slobozia X-Mailer: Mozilla 4.75 [en] (X11; U; Linux 2.2.17-21mdk i686) X-Accept-Language: en MIME-Version: 1.0 To: juerg.rietmann@pup.ch, PostgreSQL-SQL Subject: Re: how to add an new record from part of an old one References: Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200105/184 X-Sequence-Number: 3001 juerg.rietmann@pup.ch wrote:
Hi there

I need to half copy and insert new data in a new record. Please see the SQL
statement, that is not working, but i think is shows what I'd like to do.
The fields a_nr and a_kurzbez will get the values from a form and a_bez
needs to be copied from an existing auftrag.

Thanks for any help ... jr

insert into auftrag (a_nr, a_kurzbez) values (123456789, 'testtext')
(select a_bez from auftrag where a_nr='200113672732')


Try something like the folowing example:

test=# create table a (id serial, a1 text, a2 int4);
CREATE
test=# insert into a (a1, a2) values ('1221211', 12);
INSERT 580415 1
test=# insert into a (a1, a2) values ('12345', 11);
INSERT 580416 1
test=# select * from a;
 id |   a1    | a2
----+---------+----
  1 | 1221211 | 12
  2 | 12345   | 11
(2 rows)
 
test=# create table b (id serial, b1 text, b2 int4, b3 varchar(32));
CREATE
test=# insert into b (b1, b2, b3) select a1, a2, 'something else' from a where id = 1;
INSERT 580468 1
test=# select * from b;
 id |   b1    | b2 |       b3
----+---------+----+----------------
  1 | 1221211 | 12 | something else
(1 row)
 
test=#

I hope this can help you !!

George Moga,
    Data Systems Srl
    Slobozia, ROMANIA