DBeaver将SQL文件导出为具有别名列名的INSERT语句

时间:2019-07-15 21:32:35

标签: sql postgresql export resultset dbeaver

我有这个SQL查询:

SELECT
    id as address_uuid,
    parent_addresses_id as parent_address_uuid,
    CONCAT_WS(', ',
    address_street1,
    address_street2,
    parsed_city,
    parsed_state,
    parsed_postal) as address,
    parcel_master_units as units,
    fiber_type as tenancy_type,
    created_date as created_at,
    modified_date as updated_at
FROM 
    addresses
WHERE 
    parsed_city = 'Minneapolis'
AND 
    deleted != 1

任何人都知道如何将其导出为INSERT语句的SQL文件,并且其列与我的别名匹配,如下所示:

INSERT INTO addresses (address_uuid,parent_address_uuid,address,units,tenancy_type,created_at,updated_at) VALUES (...)

而不是当前导出的内容:

INSERT INTO addresses (id,parent_addresses_id,address,parcel_master_units,fiber_type,created_date,modified_date) VALUES (...)

还是其他可以处理此问题的GUI?我正在尝试迁移许多地址数据,如果我可以使INSERT语句具有新表的正确列名,这将很容易。

3 个答案:

答案 0 :(得分:0)

这个hacky解决方案有效:

SELECT
    CONCAT(id) as address_uuid,
    CONCAT(parent_addresses_id) as parent_address_uuid,
    CONCAT_WS(', ',
    address_street1,
    address_street2,
    parsed_city,
    parsed_state,
    parsed_postal) as address,
    CONCAT(parcel_master_units) as units,
    CONCAT(fiber_type) as tenancy_type,
    CONCAT(created_date) as created_at,
    CONCAT(modified_date) as updated_at
FROM 
    addresses
WHERE 
    parsed_city = 'Minneapolis'
AND deleted != 1

不确定为什么不将别名应用于导出的INSERT语句,因此,如果有人知道解决该问题的技巧,我很想知道!

答案 1 :(得分:0)

您可以在DBeaver中尝试这种基于GUI的方法。

右键单击表格->导出数据。这将打开“数据传输向导”。从选项中选择数据库。检查选项,如果很好,请单击“下一步”。这将为您提供选择“目标容器(架构)”的选项。选择所需的目标。

接下来,在“源”旁边,您将看到空白作为“目标”。单击“新建”(左下方)以创建新表。单击源表名称旁边的下拉箭头(>),这将显示列列表。然后,您可以选择列并根据要求将其重命名。此外,如果选择列的映射,则会找到更多选项来控制数据类型。

希望这对您的问题有所帮助。

答案 2 :(得分:-1)

更改当前查询:

SELECT
    id as address_uuid,
    parent_addresses_id as parent_address_uuid,
    CONCAT_WS(', ',
    address_street1,
    address_street2,
    parsed_city,
    parsed_state,
    parsed_postal) as address,
    parcel_master_units as units,
    fiber_type as tenancy_type,
    created_date as created_at,
    modified_date as updated_at ...

要包含所需的列名,因为您说“恢复为原始名称”,只需删除别名:

SELECT
    id,
    parent_addresses_id,
    CONCAT_WS(', ',
    address_street1,
    address_street2,
    parsed_city,
    parsed_state,
    parsed_postal) as address,
    parcel_master_units, 
    fiber_type,
    created_date,
    modified_date  ...