Re: Strange sequences - how to construct?
От | TIM CHILD |
---|---|
Тема | Re: Strange sequences - how to construct? |
Дата | |
Msg-id | 1340188717.307707.1634994565348@connect.xfinity.com обсуждение исходный текст |
Ответ на | Strange sequences - how to construct? (SQL Padawan <sql_padawan@protonmail.com>) |
Список | pgsql-novice |
Here is a way using multiple sequences:
drop sequence if exists controller_sequence;
drop sequence if exists odd_values;
drop sequence if exists even_values;
drop sequence if exists odd_values;
drop sequence if exists even_values;
create sequence if not exists controller_sequence;
create sequence if not exists odd_values start with 1;
create sequence if not exists even_values start with 1;
create sequence if not exists odd_values start with 1;
create sequence if not exists even_values start with 1;
create function next_my_sequence() returns integer as
$body$
declare
choose integer;
begin
choose = nextval('controller_sequence');
if choose % 2 equals then
return nextval('even_values');
else
return nextval('odd_values');
end if;
end;
$body$
language plpgsql;
$body$
declare
choose integer;
begin
choose = nextval('controller_sequence');
if choose % 2 equals then
return nextval('even_values');
else
return nextval('odd_values');
end if;
end;
$body$
language plpgsql;
-- example: get 5 sequences
select next_my_sequence(), next_my_sequence(), next_my_sequence(), next_my_sequence(), next_my_sequence();
select next_my_sequence(), next_my_sequence(), next_my_sequence(), next_my_sequence(), next_my_sequence();
On 10/22/2021 12:29 PM SQL Padawan <sql_padawan@protonmail.com> wrote:Good afternoon to everybody.I wish to construct some weird sequences.1122&c.and with 3 ones, 4 ones... &c.Now, I know how to do a simple1234using both GENERATE_SERIES and using a RECURSIVE CTE.What I would like is to be able to construct my specified sequences using *_both_* GENERATE_SERIES *_and_* RECURSIVE CTEs.Regards,SQL Padawan!Sent with ProtonMail Secure Email.
В списке pgsql-novice по дате отправления: