Re: help with serial type - Mailing list pgsql-general

From Gregory Wood
Subject Re: help with serial type
Date
Msg-id 006801c0ce77$f6ce5000$7889ffcc@comstock.com
Whole thread Raw
In response to help with serial type  (Jason <gee308@mediaone.net>)
List pgsql-general
> > I'm surprised that works at all... the name of the table is "atable",
isn't
> > it? Try this:
> >
> > INSERT INTO atable (title,name,date) VALUES ('SQL3','Toy',date('now'));
> >
> > Greg
>
> Thanks for the help.  I wrote the command out wrong in the post, I did try
the
> one that you wrote out, and it didn't update.  I used:
>
> INSERT INTO atable (title,name,date) VALUES ('SQL3','Toy',date('now'));
> Still not sure how to fix it.

I just did this on 7.1 (PostgreSQL 7.1 on i386-unknown-freebsd4.2, compiled
by GCC 2.95.2) and it worked fine:

-----
CREATE TABLE atable (
title VARCHAR(20),
name VARCHAR(20),
id SERIAL PRIMARY KEY
);
ALTER TABLE ADD COLUMN date DATE;
INSERT INTO atable (title,name,date) VALUES ('SQL3','Toy',date('now'));
INSERT INTO atable (title,name,date) VALUES ('SQL3','Toy2',date('now'));
-----

After that I tried SELECT currval('atable_id_seq'); and got the correct
value (2).

> Is it possible to rearrange columns?  I looked
> in the tutorial, but didn't find anything useful.

In relational database design, the order of the columns should not matter,
only the data layout of the database (which columns are in which table). To
the best of my knowledge, the only way to reorder the columns physically
would be to recreate the table... you can do a SELECT id,title,name,date
INTO btable FROM atable, and then rename that first table I suppose. Or
rename the table first and then do the SELECT INTO.



pgsql-general by date:

Previous
From: Boulat Khakimov
Date:
Subject: Postgres Bug (ALTER TABLE problem)
Next
From: "Geoff Caplan"
Date:
Subject: Re: Struggling to change default data location