The only place I can think of, where a %
would be doubled up in standard Postgres is inside the format()
function, commonly used for producing a query string for dynamic SQL. Compare examples here on SO.
In addition to the format specifiers described above, the special sequence
%%
may be used to output a literal%
character.
Tricky when using the modulo operator %
in a dynamic statement!
I suspect they are running dynamic SQL behind the curtains - which they generalized and simplified for the article. (The schema-qualified name of the sequence is 'insta5.table_id_seq'
and the table wouldn't be named "table".) In the process they forgot to "unescape" the modulo operator.
That's what they may actually be running:
EXECUTE format($$SELECT nextval('%I') %% 1024$$, seq_name)
INTO seq_id;