Re: How do I add a column to an existing table.

From: John Draper <crunch(at)webcrunchers(dot)com>
To: pgsql-general(at)postgreSQL(dot)org
Subject: Re: How do I add a column to an existing table.
Date: 2000-09-17 21:43:31
Message-ID: v03110701b5eae6d9b7f5@[24.12.41.181]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>Please don't take offense but there's a few points you need to
>realize:
>
>1) I'm just a volunteer and don't have time to research the
> exact sequence of commands for you, (it looks like you didn't
> even try to read the docs between getting my response and
> emailing me back)

I did read the docs and I don't understand them, and I cannot possibly
guess what commend to make... I can ONLY learn by example.

>2) you need to read the docs.

I did - over and over and over again... linearly, and reference it
constantly - their examples do NOT cover every case.

>3) in the future please post your replies back to the main list
> so that if I happen to go someplace else or miss your mail someone
> else may be able to pick it up.

Ok, I was just trying to cut down on bandwidth, thats all.
>
>read on, I'll give you more info on how to achive what you want.

>Of course you care, pg_dump can be told to dump to an output file.
>
>And don't loose it! in fact it's probably a good idea to view it
>and make sure it contains all your data then making sure you back
>it up to another machine before dropping the table.
>
>> >You then should be able to run the insert statements and get a unique
>> >key for each row.
>>
>> Again, an exact set of commands to do this, would be most helpful.
>> I'm having problems understanding the Docs. SQL is really new to me.
>
>you should be able to just run 'psql < dumpfile' and psql will run
>all the commmands in the file to do the insertion.

Do I run this from the system shell promot like "bash" or do I run it from
within the "psql" program? And where in the docs do they explain this?
>
>> >Another way would be to just add the column, then run a query to set
>> >the key == 'oid', you'd then have to create a sequence, and set it's
>> >value to 'max(key)' then make the key column's default to
>> >'nextval(''your sequewnce name'')' unfortunatly you can't make 'key'
>> >the first column.

I'm just guessing here, but would it look like this?

CREATE SEQUENCE users_seq; <--- to create the sequence

CREATE TABLE temp_users (key int DEFAULT nextval('users_seq'), first_name
char(15), last_name char(15) <etc>

Is THAT how I would do it?

John

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Geoff Russell 2000-09-17 23:56:04 Large Objects Across a Network
Previous Message Peter Eisentraut 2000-09-17 20:37:35 Re: All function parameters become NULL if one is?