Received: from shaked.cc.openu.ac.il (shaked.cc.openu.ac.il [147.233.145.65]) by hub.org (8.8.8/8.7.5) with ESMTP id EAA05146 for ; Wed, 26 Aug 1998 04:47:29 -0400 (EDT) Received: from [147.233.159.109] (herouth@mac-herouth.pc.openu.ac.il [147.233.159.109]) by shaked.cc.openu.ac.il (8.8.5/8.8.5) with ESMTP id LAA05988; Wed, 26 Aug 1998 11:47:01 +0300 (IDT) X-Sender: herouth@shaked.cc.openu.ac.il Message-Id: In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Date: Wed, 26 Aug 1998 11:48:20 +0300 To: Walt Bigelow From: Herouth Maoz Subject: Re: [SQL] copying rows Cc: pgsql-sql@postgreSQL.org At 1:38 +0300 on 26/8/98, Walt Bigelow wrote: > I have a table that stores spot info for our tape label system. I want to > be able to copy all records with a specific librarynumber back into the > same table, but with a different librarynumber. > > Something similar to this (which of course does not work) > > select into tblspotinfo (librarynumber) values ('6666') select spotnumber, > spottitle, isci, trt, date, timecode from tblspotinfo where librarynumber > = '9988'; > > Of course it does not like me overloading the select into command like > that. Is there a simple way to do this that I am just missing? I just > want to duplicate the data related to librarynumber 9988 and make the new > librarynumber 6666. It's just a matter of syntax. What you want to do is add new rows into a table. That implies an INSERT rather than a select (select into creates a new table, not inserts rows into an existing one). So, we check the syntax for INSERT to see if there is any help there. testing=> \h insert Command: insert Description: insert tuples Syntax: insert into [(...)] [values (...); | select ,... [from ] [where ]; Indeed there is! Your syntax should be: INSERT INTO tblspotinfo ( librarynumber, spotnumber, spottitle, isci, trt, date, timecode ) SELECT 6666, spotnumber, spottitle, isci, trt, date, timecode FROM tblsoptinfo WHERE librarynumber = 9988; Voila! Herouth -- Herouth Maoz, Internet developer. Open University of Israel - Telem project http://telem.openu.ac.il/~herutma