Fix some issues that cause incompatibility with postgres
Mastodon post IDs are Integers in some cases, which causes issues with Postgres since it's expecting a string. Also, func.rand is used, which doesn't work with Postgres, but func.random will generate the correct SQL regardless of the database type.
I don't have the ability to test these changes against MySQL, but the changes shouldn't break anything.