Skip site navigation (1) Skip section navigation (2)

Copying a column from one table to another

From: David Gaudine <davidg(at)alcor(dot)concordia(dot)ca>
To: pgsql-novice(at)postgresql(dot)org
Subject: Copying a column from one table to another
Date: 2006-03-15 22:12:59
Message-ID: 4418916B.6000709@alcor.concordia.ca (view raw or flat)
Thread:
Lists: pgsql-novice
Suppose I have a table "people" like this;

Name   Age
David    25
Simon   19

and a table "occupations" like this:

Name  Occupation
David  Teacher
Simon  Student

"Name", "Age", and "Occupation" are just the column names, not data.  
The names are unique and one-to-one, i.e. if there's a David in one 
table then there's exactly one David in each.

I know that if I want to display

David  25  Teacher
Simon 19  Student

I can use something like

select people.name, age, occupation from people, occupations where 
people.name=occupations.name

But, what I would like to know is, how can I copy the column 
"occupation" to the table "people"?  That is, I want to create a new 
column people.occupation and populated it from occupations.occupation.  
Feel free to point me to a relevant section of the documentation.

David


Responses

pgsql-novice by date

Next:From: george youngDate: 2006-03-16 01:52:07
Subject: Re: Copying a column from one table to another
Previous:From: Tom LaneDate: 2006-03-15 19:24:38
Subject: Re: ESTERROR

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group