3 ms·
SELECT causing changes to things makes me feel weird inside.
by bombcar 4y ago
SELECT causing changes to things makes me feel weird inside.
- pcthrowaway 4y agoThat's how every Postgres extension works (e.g. Timescale, PostGIS, etc.)
- firloop 4y agoNot just Postgres extensions, most of Postgres’ own administrative functions can be triggered in SELECT statements. e.g. pg_terminate_backend() https://www.postgresql.org/docs/current/functions-admin.html https://www.postgresql.org/docs/current/functions-admin.html
- yjftsjthsd-h 4y agoTo be quite clear, that always felt weird to me as well - something to the effect of "I thought SELECT was for reading data; why am I using it to create a replica?"
- quickthrower2 4y agoSELECT is a bit like return? return 6; or return x++; or even return (exit(0));
- colejohnson66 4y agoI think GP is saying they view SELECT as a "pure" function. A pure function doesn't modify state, so neither should SELECT.
- bombcar 4y agoYeah, from limited experience with SQL "SELECT is safe" (assuming no weirdness in sub functions or commands) but that's clearly not always the case.
- kaveet 4y agoDO $$ BEGIN PERFORM rebalance_table_shards(); END $$;