Skip to content

Instantly share code, notes, and snippets.

@bastjan
Created February 21, 2017 13:12
Show Gist options
  • Save bastjan/abdde4b5936afcd5f634dfca47c877f5 to your computer and use it in GitHub Desktop.
Save bastjan/abdde4b5936afcd5f634dfca47c877f5 to your computer and use it in GitHub Desktop.
find corrupted database fields in postgres
DO $f$
declare
read_data TEXT;
bad_id INT;
begin
FOR bad_id IN SELECT id FROM <TABLE_NAME> LOOP
begin
SELECT <TABLE_FIELD>
INTO read_data
FROM <TABLE_NAME> where id = bad_id;
read_data := substr(access_data,1000,2000);
exception
when others then
raise notice 'data for row with id % is corrupt', bad_id;
continue;
end;
end loop;
end;
$f$;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment