Created
February 21, 2017 13:12
-
-
Save bastjan/abdde4b5936afcd5f634dfca47c877f5 to your computer and use it in GitHub Desktop.
find corrupted database fields in postgres
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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