运行postgresql脚本时出现奇怪的从左到右的箭头

时间:2017-06-12 09:02:20

标签: postgresql command-line psql

我想运行大约5000行的postgresql脚本。出于职业原因,我无法分享脚本的全部内容。 但我有点像这样:

SET statement_timeout = 0;
SET lock_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;

SET search_path = public, pg_catalog;
...
ALTER TABLE ONLY public.client DROP CONSTRAINT client_pkey;
...
ALTER TABLE public.client ALTER COLUMN id DROP DEFAULT;
...
DROP SEQUENCE public.client_id_seq;
DROP TABLE public.client;
...
--
-- Name: client; Type: TABLE; Schema: public; Owner: myDB; Tablespace: 
--

CREATE TABLE client (
    id integer NOT NULL,
    libelle character varying(255)
);


ALTER TABLE client OWNER TO myDB;

--
-- Name: client_id_seq; Type: SEQUENCE; Schema: public; Owner: myDB
--

CREATE SEQUENCE client_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE client_id_seq OWNER TO myDB;

--
-- Name: client_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: myDB
--
--
-- Data for Name: client; Type: TABLE DATA; Schema: public; Owner: myDB
--

COPY client (id, libelle) FROM stdin;
0
1   XX
247 YY
248 ZZ
\.

copy语句有很多插入。但每次我运行数据库时,我会得到类似这样的东西,有很多从左到右的箭头: enter image description here

而且我不知道如何继续。当我检查数据库时,整个脚本没有完全运行。仅创建表。 请问,问题是什么?

PS:我使用Linux Debian

1 个答案:

答案 0 :(得分:2)

当您COPY FROM STDIN时,您会看到消息:

t=# copy s151 from stdin;
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.

这里的关键是

  

以反斜杠和一个句点单独结束

所以你的多个>>只意味着一个新行已从stdin添加到COPY。看到那些绝对没问题。在将\.放在其上之前,您将在每个新行上看到这些

现在关于这个问题。您的脚本有错误(我复制/粘贴了其中的一部分):

t=# \! cat so.sql
CREATE TABLE client (
    id integer NOT NULL,
    libelle character varying(255)
);
COPY client (id, libelle) FROM stdin;
0
1   XX
247 YY
248 ZZ
\.

t=# \i so.sql
CREATE TABLE
psql:so.sql:10: ERROR:  missing data for column "libelle"
CONTEXT:  COPY client, line 1: "0"

添加缺失列后(并将分隔符更改为空格以避免从网页复制时出现制表问题):

t=# \! cat so.sql
COPY client (id, libelle) FROM stdin delimiter ' ';
0 ZZ
1 XX
247 YY
248 ZZ
\.
t=# \i so.sql
COPY 4

它有效