Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres %% in function

What does the "%%" in this statement mean?

SELECT nextval(seq_name) %% 1024 INTO seq_id;

And why does Postgres say, when I use it?

operator does not exist: bigint %% integer
like image 648
outrunthewolf Avatar asked Nov 16 '25 21:11

outrunthewolf


1 Answers

Most probably, it's an artifact from translating dynamic SQL with format(), which requires to double % characters. Should be the modulo operator % if translated correctly, which also makes sense for a sharding solution or similar. Effectively, you get numbers cycling from 0 to 1023.

I suspect it's the same as we already dealt with here:

  • What does %% in PL/pgSQL mean?
like image 146
Erwin Brandstetter Avatar answered Nov 18 '25 10:11

Erwin Brandstetter