pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Herouth Maoz <herouth@oumail.openu.ac.il>
To: Walt Bigelow <walt@stimpy.com>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] copying rows
Date: Wed, 26 Aug 1998 11:48:20 +0300
Message-ID: <l03110703b2097a916b7b@[147.233.159.109]> (raw)
In-Reply-To: <Pine.LNX.4.02.9808251530500.9040-100000@alice.stimpy.com>

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 <class_name> [(<attr1>...<attrN>)]
        [values (<expr1>...<exprN>); |
        select <expr1>,...<exprN> [from <from_clause>] [where <qual>];

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





view thread (2+ messages)

Message-ID: <l03110703b2097a916b7b@[147.233.159.109]>
Permalink:  ../l03110703b2097a916b7b@%5B147.233.159.109%5D/
Also on:    postgresql.org/message-id/l03110703b2097a916b7b@[147.233.159.109]

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: herouth@oumail.openu.ac.il, walt@stimpy.com
  Subject: Re: [SQL] copying rows
  In-Reply-To: <l03110703b2097a916b7b@[147.233.159.109]>
  References: <Pine.LNX.4.02.9808251530500.9040-100000@alice.stimpy.com> <l03110703b2097a916b7b@[147.233.159.109]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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