Skip to content

Instantly share code, notes, and snippets.

@mixerp
mixerp / ownership.sql
Created August 5, 2017 09:19
Make a user owner of the whole database.
DO
$$
DECLARE this record;
BEGIN
IF(CURRENT_USER = 'db_user') THEN
RETURN;
END IF;
FOR this IN
SELECT * FROM pg_tables
@mixerp
mixerp / reset-all-sequences-in-db.sql
Created August 5, 2017 09:15
Resets all sequences in all schema in the current PostgreSQL database.
DO
$$
DECLARE _sql text;
BEGIN
WITH all_sequences
AS
(
SELECT
pg_namespace.nspname AS schema_name,
pg_class.relname AS table_name,
@mixerp
mixerp / ban-user.sql
Created March 1, 2016 20:03
PostgreSQL Rule Example
CREATE TABLE forums.banned_users
(
banned_user_id integer PRIMARY KEY REFERENCES account.users,
banned_by integer REFERENCES account.users,
reason text,
browser text,
ip_address text,
user_agent text,
audit_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT(NOW())
);