Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eradman/pg-safeupdate
A simple extension to PostgreSQL that requires criteria for UPDATE and DELETE
https://github.com/eradman/pg-safeupdate
postgresql-extension
Last synced: 17 days ago
JSON representation
A simple extension to PostgreSQL that requires criteria for UPDATE and DELETE
- Host: GitHub
- URL: https://github.com/eradman/pg-safeupdate
- Owner: eradman
- License: other
- Created: 2018-03-27T02:01:25.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-08-29T14:56:41.000Z (3 months ago)
- Last Synced: 2024-10-13T00:08:09.761Z (about 1 month ago)
- Topics: postgresql-extension
- Language: Ruby
- Homepage:
- Size: 30.3 KB
- Stars: 117
- Watchers: 7
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - eradman/pg-safeupdate - A simple extension to PostgreSQL that requires criteria for UPDATE and DELETE (Ruby)
README
Require SQL Where Clause
========================`safeupdate` is a simple extension to PostgreSQL that raises an error if
`UPDATE` and `DELETE` are executed without specifying conditions. This
extension was initially designed to protect data from accidental obliteration of
data that is writable by [PostgREST].Installation
------------Build from source using
gmake
gmake installActivate per-session by running
load 'safeupdate';
Make this mandatory for all databases and connections by adding the following to
`postgresql.conf`:shared_preload_libraries=safeupdate
Or enable for a specific database using
ALTER DATABASE mydb SET session_preload_libraries = 'safeupdate';
Options
-------Once loaded this extension can be administratively disabled by setting
SET safeupdate.enabled=0;
Examples
--------Try to update records without `WHERE` clause
UPDATE FROM rack SET fan_speed=70;
-- ERROR: UPDATE requires a WHERE clauseSelect results from a CTE that attempts to modify data:
WITH updates AS (
UPDATE rack SET fan_speed=70
RETURNING *
)
SELECT * FROM updates;
-- ERROR: UPDATE requires a WHERE clauseSet a column value for a range of records
UPDATE rack SET fan_speed=90 WHERE fan_speed=70;
Set a column value for all the records in a table
UPDATE rack SET fan_speed=90 WHERE 1=1;
News
----Notification of new releases are provided by an
[Atom feed](https://github.com/eradman/pg-safeupdate/releases.atom),
and release history is covered in the [NEWS](NEWS) file.[PostgREST]: http://postgrest.com