TablePlus / TablePlus

TablePlus macOS issue tracker
https://tableplus.com
3.47k stars 57 forks source link

Feature Request: Export Query Result as Table Schema #3441

Open yeysman opened 1 week ago

yeysman commented 1 week ago

Environment Details

Use Case Description

When working with query results, especially complex joins, users need the ability to export the result structure as a table schema definition. This feature would streamline the creation of temporary tables and facilitate entity mapping in applications.

Sample Schema

-- Base tables
CREATE TABLE employee (
    id INT,
    first_name VARCHAR,
    last_name VARCHAR,
    date_of_birth DATETIME,
    department_id INT,
    -- additional columns...
);

CREATE TABLE department (
    id INT,
    name VARCHAR,
    -- additional columns...
);

Example Query

SELECT 
    employee.id AS emplId,
    department.id AS depId,
    e.date_of_birth AS emplDob
FROM employee e
INNER JOIN department d ON d.id = e.department_id;

Desired Output Format

CREATE TABLE #queryResult1 (
    emplId INT,
    depId INT,
    emplDob DATETIME
);

Feature Requirements

  1. Column Naming Convention:

    • For aliased columns: Use the provided alias name
    • For non-aliased columns: Use format tableName_columnName Example: employee_id, department_id
  2. Data Type Mapping:

    • Preserve original data types from source columns
    • Map them to appropriate SQL data types in the generated schema
  3. Output Options:

    • copy to clipboard

Use Case Benefits

  1. Temporary Table Creation:

    • Simplifies creation of temp tables for complex query results
    • Reduces manual effort in schema definition
    • Minimizes potential type mismatch errors
  2. Entity Mapping Support:

    • Facilitates accurate AI-driven entity class generation
    • Improves code generation accuracy

Could you please review this request and let me know if it can be implemented in closest time?