RE: Serial field

Поиск
Список
Период
Сортировка
От Robby Slaughter
Тема RE: Serial field
Дата
Msg-id EPEHLKLEHAHLONFOKNHNEEMEDCAA.webmaster@robbyslaughter.com
обсуждение исходный текст
Ответ на Re: Serial field  (Jason Earl <jdearl@yahoo.com>)
Ответы RE: Serial field  (Jason Earl <jdearl@yahoo.com>)
Список pgsql-novice
Jason and Francois:

Jason: That's not how I interepreted Francois' request,
but it's  a clever approach to what sounds like a common
need in database design. And yes, using a recent version
of PostgreSQL is a good idea!

Francois: It sounds like you just want an
auto-increment field but you don't want to
values you've already have in the table.

I think your best option is to do create the table
first just using standard INTEGERs and import your
data into the table. Then do an ALTER TABLE and
change the table design.

I don't have a convienent way to try it right now
but that should work.

If it doesn't, you count always just create your
own pgplsql stored procedure that works like
a standard sequence. As far as I can tell, when
you create a SERIAL type, that's what happens
anyway. The table definition ends up having
a DEFAULT value for the serial field, which
is a function call to nextval('tablename_fieldname_seq');

You could implement the same code yourself and just
not "turn on" the function until after your original
data is entered.

Hope that helps.

-Robby

> I want to migrate a database to PostgreSQL 6.5.2
> I need an auto-increment field. I first tried the
> SERIAL type, but it
> doesn't fit my needs.
> In fact, I want to:
> 1/ keep the original INT value of my existing
> records from another server
> (say, first row can be "1", second "3", next one
> "17",...)
> 2/ have an automatic incrementation of the last
> value for a new record. For
> exemple, with the values above and a SERIAL field,
> the default value for a
> new field would be "1" (first use of the sequence)
> instead of "18" (last
> value+1)..
> I hope my english is not too obscure !
> Any advice will be welcome
> Regards
>
> --
> Frangois THOMAS
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://www.postgresql.org/search.mpl


__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html

В списке pgsql-novice по дате отправления:

Предыдущее
От: SuperDutyTA73@aol.com
Дата:
Сообщение: Best formal training for PostgreSQL use?
Следующее
От: Jason Earl
Дата:
Сообщение: RE: Serial field