Skip to content

Instantly share code, notes, and snippets.

@ivan
Created February 20, 2020 05:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivan/9e7ccc83e1dc55a8dae904e5b11ac910 to your computer and use it in GitHub Desktop.
Save ivan/9e7ccc83e1dc55a8dae904e5b11ac910 to your computer and use it in GitHub Desktop.
pg_tmp_lets_me_truncate
#!/bin/sh
uri=$(pg_tmp)
psql --no-psqlrc "$uri" -c "SELECT SESSION_USER, CURRENT_USER;"
psql --no-psqlrc "$uri" -c "CREATE TABLE dirs (id bigserial PRIMARY KEY);"
psql --no-psqlrc "$uri" -c "REVOKE TRUNCATE ON dirs FROM current_user;"
psql --no-psqlrc "$uri" -c "TRUNCATE dirs;"
@ivan
Copy link
Author

ivan commented Feb 20, 2020

# ./pg_tmp_weirdness
 session_user | current_user
--------------+--------------
 at           | at
(1 row)

CREATE TABLE
REVOKE
TRUNCATE TABLE

@ivan
Copy link
Author

ivan commented Feb 20, 2020

postgresql 12.2 on NixOS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment