Create custom sequence for PostgreSQL Primary Key with auto-increment.

You can use standard sequence and formatting functions to customise the value.
to_char(nextval('test_seq'), 'TS0000000FM') 
FM : prefix fill mode (suppress padding blanks and trailing zeroes)

CREATE SEQUENCE test_seq;
CREATE TABLE test_table
(
 s_no CHAR(8) NOT NULL DEFAULT to_char(nextval('test_seq'), 'TS0000000FM'),
 txt TEXT
);
ALTER SEQUENCE test_seq OWNED BY test_table.s_no; 

You can read more on this example and about postgresql formatting functions in following links.

sources : 
http://www.quora.com/How-do-I-create-a-custom-sequence-for-a-PostgreSQL-primary-key-e-g-A0000001
http://www.postgresql.org/docs/9.4/static/functions-formatting.html

Popular posts from this blog

npm refusing to install as a dependency of itself

How to call javascript functions from VB.NET and using WebBrowser Control