Re: ?How create a one serial decimal(500,0) column or simulate itwith bigint multicolumns serial?
От | Dani |
---|---|
Тема | Re: ?How create a one serial decimal(500,0) column or simulate itwith bigint multicolumns serial? |
Дата | |
Msg-id | CAEXvJLeXLzpmceAKnhFEL=1pd_DuaW2_aY29gKSArPiooFPv-A@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: ?How create a one serial decimal(500,0) column or simulate itwith bigint multicolumns serial? ("David G. Johnston" <david.g.johnston@gmail.com>) |
Ответы |
Re: ?How create a one serial decimal(500,0) column or simulate itwith bigint multicolumns serial?
|
Список | 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
)
------------------------------ ------------------------
AS
$$
Update decimal_hold0 Set actual_value = actual_value + 1 where id = miid Returning actual_value;
$$ LANGUAGE SQL;
Really Many Thanks in Advance!!! :-) 
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'"
=>Select * from decimal_hold0;
=> result is"1, 0, '1a_column_for_money_dindin_
------------------------------ ------------------------
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
)
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)
:-)
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 :-)

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:-)
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 по дате отправления: