How to export table structure in postgresql

You can use a variety of methods to export data and object structures from your databases. These methods include usage of various generators, data extractors, and shortcuts. Also, you can export data in TXT, CSV, JSON, XML, Markdown, Excel, and other formats. You can select a predefined extractor or create your own.

In DataGrip, you export object structures and data separately. It means that you can export a structure of a table or a view and then export data from these objects. The full data dump is available for PostgreSQL and MySQL with the help of mysqldump and pg_dump. The full data dump includes structures of all database objects and data of these objects in a single file. For more information, see Create a full data dump for MySQL and PostgreSQL.

Exporting object structures

Data definition language (DDL) defines the structure of a database, including rows, columns, tables, indexes, and other elements. In DataGrip, you can generate data definition structures by using shortcuts with predefined settings or by using the SQL Generator and customize the export settings.

The following video shows how you can generate SQL for existing objects.

Generate DDL definitions for database objects

  • In the Database Explorer (), right-click a database object and select Ctrl+Alt+G.

    On the right toolbar, you can find the following controls:

    • : copy output to the clipboard.

    • : save output to a file.

    • : open output in a query console.

Change output settings of the SQL Generator

  1. In the Database Explorer (), right-click a database object (for example, a table) and select Ctrl+Alt+G.

  2. In the SQL Generator tool window, click the File Output Options icon ().

  3. From the Layout list, select a method that you want to use:

    • File per object by schema: generates a set of SQL files sorted in folders by schemas.

    • File per object by schema and database: generates a set of SQL files sorted in folders by schemas and databases.

    • File per object: generates a set of SQL files.

    • File per object with order: generates a numbered set of SQL files.

Generate a DDL definition to the query console

  • In the Database Explorer (), right-click a database object and select .

Generate a DDL definition to the clipboard

  • In the Database Explorer (), right-click a database object and select .

    If your database stores DDL of the object, you can retrieve DDL from the database by selecting the Request and Copy Original DDL.

Export data

You can export database data as SQL INSERT and UPDATE statements, TSV and CSV, Excel, Markdown, HTML tables and JSON format. When you export to a file, a separate file is created for each individual table or view.

To configure CSV extractors, see Configure an extractor for delimiter-separated values. In CSV settings, you can set separators for rows and headers, define text for NULL values, specify quotation, create new extractors for formats with delimiter-separated values.

To export data in binary formats (for example, XLSX), use the Export Data dialog.

Before DataGrip 2020.1, if you select the default extractor from the list, you set this extractor as default for the whole IDE. Beginning from DataGrip 2020.1, you set the extractor for a single table. If you open a different table, the extractor defaults to CSV.

Export data from the Database Explorer

  1. In the Database Explorer (), right-click a database object and navigate to Export Data to Files.

  2. In the Export Data dialog, customize the following settings:

    • Extractor: select the export format (for example, Excel (xlsx)).

    • Transpose: select to export data in the transposed view. In this view, the rows and columns are interchanged.

    • Add column header: adds a row with column names at the beginning of the CSV list.

    • Add row header: adds a column with enumeration of rows.

    • Output file: select a file that will store the data.

  3. To copy the generated script to the clipboard, click Copy to Clipboard. To save the script to a file, click Export Data to Files.

Export data from the data editor

  • To export data to a file, open a table or a result set, click the Export Data icon (). Configure the export settings and click Export to File.

  • To export the whole result or the whole table to the clipboard, open a table or a result set, right-click the result or the table and select Export Table to Clipboard.

    In contrast to the Export to Clipboard action, the Copy action Ctrl+C only copies the selection or all the rows on the current page. To copy rows on the current page, double-click the table and press Ctrl+C. Alternatively, click a cell, press Ctrl+A and then Ctrl+C. To configure a number of rows on a page, see Set a number of rows in the result set.

Export data from a MongoDB collection

  1. Right-click the collection that you want to export and select Export Data to File.

  2. In the Export Data dialog, click the Extractor list and select JSON.

    The output of this operation is MongoDB Extended JSON. Read about MongoDB Extended JSON in MongoDB Extended JSON (v2) at

Create a full data dump for MySQL and PostgreSQL

You can create backups for database objects (for example a schema, a table, or a view) by running mysqldump for MySQL or pg_dump for PostgreSQL. mysqldump and pg_dump are native MySQL and PostgreSQL tools. They are not integrated into DataGrip. You can read about them at and

Export data with mysqldump or pg_dump

  1. In the Database Explorer (), right-click a database object and navigate to:

    • Export with "mysqldump": for MySQL data sources. The mysqldump tool is located in the root/bin directory of the MySQL installation directory.

    • Export with "pg_dump": for PostgreSQL data sources. pg_dump, pg_dump_all, pg_restore tools are all located in the bin folder of the PostgreSQL.

  2. In the Export with <dump_tool> dialog, specify the path to the dump tool executable in the Path to <dump_tool> field.

    (Optional) Edit the command-line options in the lower part of the dialog.

  3. Click Run.

Last modified: 04 August 2022

How do I export a table from PostgreSQL?

You can Postgres Export to CSV in 3 ways, all slightly different..
Method 1: Postgres Export to CSV using the COPY Command..
Method 2: Postgres Export to CSV using the copy Command..
Method 3: Postgres Export to CSV using the pg_dump..

How do I get PostgreSQL schema?

3 Ways to list all schemas in PostgreSQL.
Using SQL Query. We can list all PostgreSQL schemas using the (ANSI) standard INFORMATION_SCHEMA: SELECT schema_name FROM information_schema.schemata; ... .
Using psql. If you are using psql, you can list all schemas simply by using the following command: \dn..
With ERBuilder Data Modeler..

How do I export a schema?

Schema Export and Import.
Select a connection, a schema to export, export script file name and location. Click Next..
Select Structure and Data, check Include all objects. ... .
Set the export options. ... .
Specify the errors processing behavior and logging options. ... .
Select whether to open the export script file in SQL Editor..

How do I export a Postgres database schema pgAdmin?

Step 1: Visit your schema section and select the table you wish to export. Step 2: Right-click on the table name to show up the available options. Step 3: Select the “Import/Export” option. When you click on it, the export data pgAdmin window will appear.