Git Product home page Git Product logo

postgres-to-csv's Introduction

PostgreSQL Data Exporter

Description

This Python script connects to a PostgreSQL database, fetches data from a specified table, and exports the data to a CSV file. Additionally, it saves images stored as base64 strings in the database to individual image files.

Configuration

Prerequisites

  • Python 3.10 or higher
  • PostgreSQL database with the required table
  • Python packages listed in requirements.txt

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/your-repository.git
    cd your-repository
  2. Install dependencies:

    pip install -r requirements.txt
  3. Rename the project file .env.example to .env and set the following environment variables:

    POSTGRES_DB=your_database_name
    POSTGRES_USER=your_database_user
    POSTGRES_PASSWORD=your_database_password
    POSTGRES_HOST=your_database_host
    POSTGRES_PORT=your_database_port
    
    PGADMIN_DEFAULT_EMAIL=[email protected]
    PGADMIN_DEFAULT_PASSWORD=xxx

Usage

  1. Run the script:

    python main.py

    This will connect to the PostgreSQL database, fetch data from the specified table, and export it to a CSV file (output.csv) in the project root. Image files will be saved in the images directory.

  2. Customize SQL Query (Optional):

    Edit the SQL query in the DataProcessor class within main.py to fetch data based on your specific requirements:

    # Customize your SQL query here
    cur.execute("SELECT * FROM your_schema.your_table")

    Replace your_schema and your_table with your specific schema and table names.

  3. View the Output:

    The exported CSV file (output.csv) will contain the selected data columns. Image files will be saved in the images directory with filenames generated based on the first two columns of the fetched data.

License

This project is licensed under the MIT License - see the LICENSE file for details.

postgres-to-csv's People

Contributors

macktireh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.