plpgsql - Instragram's UUID Creation Failing in PostgreSQL 9.3.5 with the error "operator does not exist: bigint %% integer" -


i'm trying implement instagram's uuid talked in post: http://instagram-engineering.tumblr.com/post/10853187575/sharding-ids-at-instagram

but keep getting error: operator not exist: bigint %% integer

my implementation looks this:

create sequence table_id_seq;  create or replace function next_id(out result bigint) $$ declare     our_epoch bigint := 1314220021721;     seq_id bigint;     now_millis bigint;     shard_id int := 5; begin     select nextval('table_id_seq') %% 1024 seq_id;     select floor(extract(epoch clock_timestamp()) * 1000) now_millis;     result := (now_millis - our_epoch) << 23;     result := result | (shard_id << 10);     result := result | (seq_id); end; $$ language plpgsql;  create table items (    id bigint not null default next_id(),    path character(255) not null default ''::bpchar,    constraint items_pkey primary key (id) ) (   oids=false ); --##check table instagram=# \d items                  table "public.items"  column |      type      |          modifiers --------+----------------+-----------------------------  id     | bigint         | not null default next_id()  path   | character(255) | not null default ''::bpchar indexes:     "items_pkey" primary key, btree (id) 

my environments:

postgresql 9.3.5 on x86_64-apple-darwin13.2.0, compiled apple llvm version 5.1 (clang-503.0.40) (based on llvm 3.4svn), 64-bit 

i keep getting error:

insert items ("path") values('/var/images/xxx.jpg');  error:  operator not exist: bigint %% integer line 1: select nextval('table_id_seq') %% 1024                                    ^ hint:  no operator matches given name , argument type(s). might need add explicit type casts. query:  select nextval('table_id_seq') %% 1024 context:  pl/pgsql function next_id() line 8 @ sql statement 

this line:

select nextval('table_id_seq') %% 1024 seq_id; 

should become:

select nextval('table_id_seq') % 1024 seq_id; 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -