Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stray line breaks spoil source code on dump/restore

To be concise: dump/restore process makes my functions’ source code look ugly! God knows why, but something adds extra line breaks to my beautifully formatted source code in a way that makes me really mad (and makes it harder to read my code). Just a small illustration of what happens after I restore my database:

CREATE OR REPLACE FUNCTION f_tr_std()
  RETURNS trigger AS
$BODY$







begin







  /* Standard trigger function */







  if ( tg_when <> 'BEFORE' ) then







    raise exception 'This must be a "before"-trigger only: "%"', tg_name;







  end if;















  if ( tg_level <> 'ROW' ) then







    raise exception 'This must be a row-level trigger: "%"', tg_name;







  end if;















end;







$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION f_tr_std() OWNER TO postgres;

The header and the footer were generated by pgAdmin. The rest is my own code.

PG version: 9.0.1 OS : Windows XP

Contents of bat file I use for dump:

@echo off
set curr_dir=%CD%
pg_dump --blobs --format=c --compress=9 --verbose --host=localhost --port=5432 -U postgres rc2_dev > "%curr_dir%\dump.bak"
pause

Contents of bat file for restore is irrelevant, I reckon, because inside the dump source is damaged already.

I have absolutely no idea what causes such a weird behavior!!! Any help would be much appreciated.

like image 830
ua.Skywalker Avatar asked Nov 05 '22 06:11

ua.Skywalker


1 Answers

In my case the issue was with using > to redirect the output. If I rather use -f to let pg_dump write straight to the file then I get nicely formatted output.

So your example will become: pg_dump --blobs --host=localhost --port=5432 -U postgres -f "%curr_dir%\dump.bak" rc2_dev

like image 96
user677686 Avatar answered Nov 09 '22 17:11

user677686