0

I'd like to ask if it is possible to handle dropping table command and break it if some conditions are not met?

Kara
  • 6,115
  • 16
  • 50
  • 57
John Smith
  • 173
  • 2
  • 10
  • 2
    Please try to write a more detailed question if you want help in future. The more you make the reader guess, the more likely they are to waste their time and yours answering something different to what you thought you were asking. Also, **what have you already tried**, researched, etc? And finally, *always include your exact PostgreSQL version in all questions*. – Craig Ringer Jul 02 '13 at 07:46

1 Answers1

2

I'm going to guess that you are trying to ask:

How do I prevent a DROP TABLE from succeeding based on certain application-defined conditions

If so, your only built-in option is to use permissions. See GRANT and REVOKE in the PostgreSQL manual.

If you want something more complex, you can write a ProcessUtility_hook, but this requires that you write an extension in C that is compiled and loaded into the server.

Writing a ProcessUtility_hook isn't actually too hard, but there are differences between the PostgreSQL 9.2 and 9.3 definitions that mean you'll need separate extensions. Here's a basic example: https://github.com/ringerc/scrapcode/tree/master/postgresql/example_processutility_hook and here's a ProcessUtility hook that actually does something useful: https://github.com/ringerc/postgres/blob/bdr-reject-unsafe-commands/contrib/bdr/bdr_commandfilter.c

If you don't have C programming experience and some time, a ProcessUtility_hook isn't for you.

See also: How to prevent table from being dropped?

Community
  • 1
  • 1
Craig Ringer
  • 307,061
  • 76
  • 688
  • 778