pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
how to add an new record from part of an old one
2+ messages / 2 participants
[nested] [flat]

* how to add an new record from part of an old one
@ 2001-05-17 12:32  juerg.rietmann@pup.ch
  0 siblings, 1 reply; 2+ messages in thread

From: juerg.rietmann@pup.ch @ 2001-05-17 12:32 UTC (permalink / raw)
  To: pgsql-sql

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')


============================================
PFISTER + PARTNER, SYSTEM - ENGINEERING AG
Juerg Rietmann
Grundstrasse 22a
6343 Rotkreuz
Switzerland

phone: +4141 790 4040
fax: +4141 790 2545
mobile: +4179 211 0315
============================================




^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: how to add an new record from part of an old one
@ 2001-05-17 14:28  George Moga <george@dsn.ro>
  parent: juerg.rietmann@pup.ch
  0 siblings, 0 replies; 2+ messages in thread

From: George Moga @ 2001-05-17 14:28 UTC (permalink / raw)
  To: pgsql-sql

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
juerg.rietmann@pup.ch wrote:
<blockquote TYPE=CITE>Hi there
<p>I need to half copy and insert new data in a new record. Please see
the SQL
<br>statement, that is not working, but i think is shows what I'd like
to do.
<br>The fields a_nr and a_kurzbez will get the values from a form and a_bez
<br>needs to be copied from an existing auftrag.
<p>Thanks for any help ... jr
<p>insert into auftrag (a_nr, a_kurzbez) values (123456789, 'testtext')
<br>(select a_bez from auftrag where a_nr='200113672732')</blockquote>

<p><br>Try something like the folowing example:
<p><tt>test=# create table a (id serial, a1 text, a2 int4);</tt>
<br><tt>CREATE</tt>
<br><tt>test=# insert into a (a1, a2) values ('1221211', 12);</tt>
<br><tt>INSERT 580415 1</tt>
<br><tt>test=# insert into a (a1, a2) values ('12345', 11);</tt>
<br><tt>INSERT 580416 1</tt>
<br><tt>test=# select * from a;</tt>
<br><tt>&nbsp;id |&nbsp;&nbsp; a1&nbsp;&nbsp;&nbsp; | a2</tt>
<br><tt>----+---------+----</tt>
<br><tt>&nbsp; 1 | 1221211 | 12</tt>
<br><tt>&nbsp; 2 | 12345&nbsp;&nbsp; | 11</tt>
<br><tt>(2 rows)</tt>
<br><tt>&nbsp;</tt>
<br><tt>test=# create table b (id serial, b1 text, b2 int4, b3 varchar(32));</tt>
<br><tt>CREATE</tt>
<br><tt>test=# insert into b (b1, b2, b3) select a1, a2, 'something else'
from a where id = 1;</tt>
<br><tt>INSERT 580468 1</tt>
<br><tt>test=# select * from b;</tt>
<br><tt>&nbsp;id |&nbsp;&nbsp; b1&nbsp;&nbsp;&nbsp; | b2 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
b3</tt>
<br><tt>----+---------+----+----------------</tt>
<br><tt>&nbsp; 1 | 1221211 | 12 | something else</tt>
<br><tt>(1 row)</tt>
<br><tt>&nbsp;</tt>
<br><tt>test=#</tt>
<p>I hope this can help you !!
<p>George Moga,
<br>&nbsp;&nbsp;&nbsp; Data&nbsp;Systems Srl
<br>&nbsp;&nbsp;&nbsp; Slobozia, ROMANIA
<br>&nbsp;
<br>&nbsp;</html>




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2001-05-17 14:28 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-05-17 12:32 how to add an new record from part of an old one juerg.rietmann@pup.ch
2001-05-17 14:28 ` George Moga <george@dsn.ro>

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