0

我想在 vertica 中导出表数据并生成一个 SQL INSERT 脚本。我导出了表模式并生成了一个 SQL 脚本。有没有办法在vertica中导出表格数据?

谢谢你。

4

1 回答 1

1

您可以做的是编写一个将其输出放入文件的 vsql 脚本。

脚本 exp.sql:

-- don't align
\a
-- tuples only
\t
\pset fieldsep '|'
-- write to workfile.sql
\o workfile.sql
-- get the create table statement into the workfile

SELECT EXPORT_OBJECTS('','public.foo',FALSE);
-- put the COPY command for in-line data into the workfile
SELECT 'COPY public.foo FROM STDIN DELIMITER ''|'';';
-- export the table's data
SELECT * FROM public.foo;
-- append a backslash-dot line to mark the end of the input of the copy command.
SELECT '\.'; 

生成的 workfile.sql:

CREATE TABLE public.foo
(
    id numeric(37,15),
    first_name varchar(256),
    last_name varchar(256),
    hire_dt timestamp
);


CREATE PROJECTION public.foo
(
 id,
 first_name,
 last_name,
 hire_dt
)
AS
 SELECT foo.id,
        foo.first_name,
        foo.last_name,
        foo.hire_dt
 FROM public.foo
 ORDER BY foo.id,
          foo.first_name,
          foo.last_name,
          foo.hire_dt
UNSEGMENTED ALL NODES;

COPY public.foo FROM STDIN DELIMITER '|';
1.000000000000000|Arthur|Dent|2017-02-05 00:00:00
2.000000000000000|Ford|Prefect|2017-02-05 00:00:00
3.000000000000000|Zaphod|Beeblebrox|2017-02-05 00:00:00
4.000000000000000|Tricia|McMillan|2017-02-05 00:00:00
 [ . . . ]
41.000000000000000|Lunkwill|Lunkwill|2017-02-05 00:00:00
42.000000000000000|Fook|Fook|2017-02-05 00:00:00
\.
于 2020-02-08T15:58:26.330 回答