Re: ?How create a one serial decimal(500,0) column or simulate itwith bigint multicolumns serial? - Mailing list pgsql-novice

From Dani
Subject Re: ?How create a one serial decimal(500,0) column or simulate itwith bigint multicolumns serial?
Date
Msg-id CAEXvJLeXLzpmceAKnhFEL=1pd_DuaW2_aY29gKSArPiooFPv-A@mail.gmail.com
Whole thread Raw
In response to Re: ?How create a one serial decimal(500,0) column or simulate itwith bigint multicolumns serial?  ("David G. Johnston" <david.g.johnston@gmail.com>)
Responses Re: ?How create a one serial decimal(500,0) column or simulate itwith bigint multicolumns serial?
List pgsql-novice
Hi!
  Thanks for the quotes!

  My need is one column per table (primary id and auto_increment) and bigger max value than bigint :-). for now the max value for a sequence
in Postgresql is bigint.

  Examples of one possible solution:

-------------------------------------------------------
CREATE TABLE decimal_hold0
(
    id bigserial not null primary key,
    actual_value numeric(1000,0) not null default 0,
    comment text not null
)
------------------------------------------------------
in first time use => Insert into decimal_hold0(comment) Values ('1a_column_for_money_dindin_table_seq');
optional (just for better understanding)
   =>Select * from decimal_hold0;
   => result is"1, 0, '1a_column_for_money_dindin_table_seq'"
------------------------------------------------------
create or replace function next_value(miid bigint) returns decimal(1000, 0)
AS
$$
    Update decimal_hold0 Set actual_value = actual_value + 1 where id = miid Returning actual_value;
$$ LANGUAGE SQL;
-------------------------------------------------------
create table money_dindin (
    id decimal(1000, 0) not null primary key default next_value(1),
    eba text
)

the real thing is showing in money_dindin.id :-)

insert into money_dindin (eba) Values ('eba1'), ('eba2'), ('eba3'), ('eba4'), ('eba5'), ('eba6')

testes=# select * from money_dindin ;
 id | eba 
----+------
  1 | eba1
  2 | eba2
  3 | eba3
  4 | eba4
  5 | eba5
  6 | eba6
(6 registros)

:-)
My renew question(s) is
1) how make function next_value   thread safe and transaction safe (or is this already safe? )
2) how simulate a sequence with type Decimal(x, 0)
3) and se possible, get ride the decimal_hold0 table :-)

Any Ideia is Wellcome :-)

Really Many Thanks in Advance!!! :-)

2018-01-07 6:45 GMT-02:00 David G. Johnston <david.g.johnston@gmail.com>:
On Saturday, January 6, 2018, Dani <danielcheagle@gmail.com> wrote:
Hi! All!

I Need create a one decimal serial column or simulate it with multiple columns of bigint.

You will need to write the logic yourself using an insert triggers - default nextval(sequence-name) isn't going to work.

David J.




--
"There are many plans in the Human heart, But
 is the Lord's Purpose that prevails"

"Existem Muitos planos e desejos no coração Humano, MAS
são os Propósitos do Senhor que prevalecem"

  []'s Dani:-)

pgsql-novice by date:

Previous
From: Dani
Date:
Subject: Re: is column order important when creating a multi-column uniqueness constraint?
Next
From: "David G. Johnston"
Date:
Subject: Re: ?How create a one serial decimal(500,0) column or simulate itwith bigint multicolumns serial?