2

We have our long-used internal db naming conventions. For example: suffix for indexes is "_ix", for foreign key - "_fk".

These conventions are conflicting with default postgresql naming conventions: "_idx" for index and "_fkey" for foreign key.

For example. If i create index and don't define index name explicit like this CREATE INDEX ON a (id); then i'll get such index name: a_id_idx. But according to our conventions, which are used not only for postgresql, there must be a_id_ix.

The best way would be to change autogenerated naming pattern to match our conventions. Seems it should be simple but i can't find how it can be done.

Any solutions?

4
  • If you want non-default names, set nondefault names. Commented Sep 6, 2017 at 10:56
  • [I still think it is a bad idea,but] postgresql.org/docs/9.6/static/sql-alterindex.html ALTER INDEX [ IF EXISTS ] name RENAME TO new_name; Commented Sep 6, 2017 at 11:00
  • @CraigRinger, there are 2 reasons why i searching ability to change the defaults: 1. There is serial type (quite convenient) generating sequence with name {table_name}_{column_name}_seq and i can't define name explicitly without manual sequence creation 2. It is wrong to forbid using autogeneration at all if there is alternative. But if i can't change the postgres defaults at global level then probably i will have to add some rules in our conventions that prohibit the use of serial type and some other features. Commented Sep 6, 2017 at 11:21
  • You can't change the PostgreSQL name generation. Commented Sep 6, 2017 at 12:35

1 Answer 1

0
CREATE INDEX index_name ON a (id);
Sign up to request clarification or add additional context in comments.

4 Comments

In some cases i can't define explicit name. For example: for serial column type postgresql generates sequence with name {table_name}_{column_name}_seq, but i need {table_name}_seq.
@keddok: yes you can: create sequence some_table_seq; create table some_table (id integer default nextval('some_table_seq')); alter sequence some_table_seq owned by some_table.id;
Thanks, @a_horse_with_no_name. But understand that there are other ways. I don't wanna prohobit the use of serial type, it is quite convenient. I just wanna to change defaults in postgresql.
@keddok: then you need to change the Postgres source and compile your own version

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.