Обсуждение: is it easy to change the create sequence algorithm?

Поиск
Список
Период
Сортировка

is it easy to change the create sequence algorithm?

От
Kevin Brannen
Дата:
I see in the docs that when I create a column that is of type SERIAL, 
the engine automatically creates the sequence for me, named 
TABLE_COLUMN_seq.  That's great until the table name + column name 
lengths are > 27 chars, then it starts chopping, and you guessed it, I 
have multiple table/column combinations that don't differ until after 
that length.

Is there a way to influence the "create sequence" generator with a 
directive, hint, set value, whatever, to be something else?  (e.g. 
COLUMN_seq if I guarantee all the columns are unique)

Yes I know that I could create the sequence myself, but the engine does 
such a good job. :-)

Thanks,
Kevin



Re: is it easy to change the create sequence algorithm?

От
"Josh Berkus"
Дата:
Kevin,

> I see in the docs that when I create a column that is of type SERIAL,
> the engine automatically creates the sequence for me, named
> TABLE_COLUMN_seq.  That's great until the table name + column name
> lengths are > 27 chars, then it starts chopping, and you guessed it,
> I have multiple table/column combinations that don't differ until
> after that length.

This would require hacking the Postgres source code.

Sure you don't wanna just create the sequences manually?

If you're sure, post your question to psql-Hackers to find out where
the SERIAL code is located.

-Josh


Re: is it easy to change the create sequence algorithm?

От
Andrew Hammond
Дата:
Well, the quickest solution I can think of off hand is to not use 
SERIAL.  Instead, do it manually, like this:

DROP SEQUENCE my_seq;

CREATE SEQUENCE my_seq;

DROP TABLE my_table;

CREATE TABLE my_table (
   my_table_id INTEGER DEFAULT nextval('my_seq') PRIMARY KEY,
   ...

);


Kevin Brannen wrote:

> I see in the docs that when I create a column that is of type SERIAL, 
> the engine automatically creates the sequence for me, named 
> TABLE_COLUMN_seq.  That's great until the table name + column name 
> lengths are > 27 chars, then it starts chopping, and you guessed it, I 
> have multiple table/column combinations that don't differ until after 
> that length.
>
> Is there a way to influence the "create sequence" generator with a 
> directive, hint, set value, whatever, to be something else?  (e.g. 
> COLUMN_seq if I guarantee all the columns are unique)
>
> Yes I know that I could create the sequence myself, but the engine 
> does such a good job. :-)
>
> Thanks,
> Kevin
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org