Re: Insert based in a select

From: Phillip Smith <phillip(dot)smith(at)weatherbeeta(dot)com(dot)au>
To: Ezequias Rodrigues da Rocha <ezequias(dot)rocha(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Insert based in a select
Date: 2007-02-25 01:23:15
Message-ID: 1172366595.4925.10.camel@phillip-desktop
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

INSERT INTO second_table (master_id) SELECT id FROM master_table ORDER
BY id;

Was it important to you that the id and master id in the second table
match up? ie, 1 and 10, 2 and 20, 3 and 30 - not 1 and 30, 2 and 10, 3
and 20 etc...

~p

On Sat, 2007-02-24 at 21:06 -0300, Ezequias Rodrigues da Rocha wrote:

> Hi list,
>
> Could someone help me with this problem
>
> I have a table like this
>
> Master table
>
> id number
> 10 9898398398
> 20 9938378390
> 30 9873636736
>
> and I want to make an insert into a table with this structure:
>
> Secondary table
>
> id(sequence), master_id
> 1 10
> 2 20
> 3 30
>
> It is possible to make this insert based in all records of my master table ?
>
> Any help would be very welcomed.
>
> Best Regards
> Ezequias
>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: You can help support the PostgreSQL project by donating at
>
> http://www.postgresql.org/about/donate

*******************Confidentiality and Privilege Notice*******************

The material contained in this message is privileged and confidential to
the addressee. If you are not the addressee indicated in this message or
responsible for delivery of the message to such person, you may not copy
or deliver this message to anyone, and you should destroy it and kindly
notify the sender by reply email.

Information in this message that does not relate to the official business
of Weatherbeeta must be treated as neither given nor endorsed by Weatherbeeta.
Weatherbeeta, its employees, contractors or associates shall not be liable
for direct, indirect or consequential loss arising from transmission of this
message or any attachments

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Rodrigo De León 2007-02-25 06:07:35 Re: [SQL] Change a field to sequence (serial)
Previous Message Ezequias Rodrigues da Rocha 2007-02-25 00:06:46 Insert based in a select