Removing comments from pg_dump output

When PostgreSQL is running pg_dump, it inserts some comments for each item, as shown below.

--
-- Name: my_table; Type: TABLE; Schema: account; Owner: user; Tablespace:
--

CREATE TABLE my_table(
    id integer
);

--
-- Name: my_seq; Type: SEQUENCE; Schema: account; Owner: user
--

CREATE SEQUENCE my_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;

Is it possible to force them to pg_dumpbe deleted (deleted)? I would like to get only:

CREATE TABLE my_table(
    id integer
);

CREATE SEQUENCE my_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
+4
source share
4 answers

On a UNIX operating system, I would do it like this:

pg_dump [options] mydatabase | sed -e '/^--/d' >mydatabase.dmp
+4
source

Postgres 11 + ( ), ( ), , , .

, Postgres 10!

+2

, - . , . , . Julia :

run(pipeline(`pg_dump -d test`,"testdump.sql"))

testdump.sql, . . , , @LaurenzAlbe:

run(pipeline(`cat testdump.sql`,`sed -e '/^--/d'`,"testdump2.sql"))

, , , testdump2. , .

, , @LaurenzAlbe, , . , bash Python .

+1

2 SQL:

  • SQL (), . , .

  • SQL , , IO .

, SQL , .

PostgreSQL pg-minify, :

  • SQL
  • SQL ( compress)

const minify = require('pg-minify');
const fs = require('fs');

fs.readFile('./sqlTest.sql', 'utf8', (err, data) => {
    if (err) {
        console.log(err);
    } else {
        console.log(minify(data));
    }
});
0

Source: https://habr.com/ru/post/1668282/


All Articles