将数据插入Postgresql表时遇到麻烦

时间:2019-04-12 06:19:08

标签: postgresql

我正在尝试将一些数据插入表中,但无法执行此操作。我得到的错误是-“插入时或附近出现语法错误”。

我创建的表-

CREATE TABLE EMP
       (EMPNO integer NOT NULL,
        ENAME VARCHAR(10),
        JOB VARCHAR(9),
        MGR integer,
        HIREDATE DATE,
        SAL integer,
        COMM integer,
        DEPTNO integer)

我要插入的数据-

INSERT INTO EMP VALUES
        (7369, 'SMITH',  'CLERK',     7902,
        '1980-12-17',  800, NULL, 20)
INSERT INTO EMP VALUES
        (7499, 'ALLEN',  'SALESMAN',  7698,
        '1981-2-20', 1600,  300, 30)
INSERT INTO EMP VALUES
        (7521, 'WARD',   'SALESMAN',  7698,
        '1981-2-22', 1250,  500, 30)
INSERT INTO EMP VALUES
        (7566, 'JONES',  'MANAGER',   7839,
        '1981-4-2',  2975, NULL, 20)
INSERT INTO EMP VALUES
        (7654, 'MARTIN', 'SALESMAN',  7698,
        '1981-9-28', 1250, 1400, 30)
INSERT INTO EMP VALUES
        (7698, 'BLAKE',  'MANAGER',   7839,
        '1981-5-1',  2850, NULL, 30)

第二条插入语句或代码的第四行中发生错误。

2 个答案:

答案 0 :(得分:0)

您需要像这样修改脚本。

INSERT INTO EMP VALUES
        (7369, 'SMITH',  'CLERK',     7902,
        '1980-12-17',  800, NULL, 20);
INSERT INTO EMP VALUES
        (7499, 'ALLEN',  'SALESMAN',  7698,
        '1981-2-20', 1600,  300, 30);
INSERT INTO EMP VALUES
        (7521, 'WARD',   'SALESMAN',  7698,
        '1981-2-22', 1250,  500, 30);
INSERT INTO EMP VALUES
        (7566, 'JONES',  'MANAGER',   7839,
        '1981-4-2',  2975, NULL, 20);
INSERT INTO EMP VALUES
        (7654, 'MARTIN', 'SALESMAN',  7698,
        '1981-9-28', 1250, 1400, 30);
INSERT INTO EMP VALUES
        (7698, 'BLAKE',  'MANAGER',   7839,
        '1981-5-1',  2850, NULL, 30);

或者,像这样。

INSERT INTO EMP VALUES
(7369, 'SMITH', 'CLERK',7902,'1980-12-17',  800, NULL, 20),
(7499, 'ALLEN', 'SALESMAN',7698,'1981-2-20', 1600,  300, 30),
(7521, 'WARD', 'SALESMAN', 7698,'1981-2-22', 1250,  500, 30),
(7566, 'JONES','MANAGER', 7839,'1981-4-2',  2975, NULL, 20),
(7654, 'MARTIN','SALESMAN',7698,'1981-9-28', 1250, 1400, 30),
(7698, 'BLAKE','MANAGER',7839,'1981-5-1',  2850, NULL, 30);

我个人比较喜欢最后一个。

答案 1 :(得分:0)

尝试一下

 INSERT INTO EMP VALUES
            (7369, 'SMITH',  'CLERK',7902,'1980-12-17',  800, NULL, 20),
            (7499, 'ALLEN',  'SALESMAN',7698,'1981-2-20', 1600,  300, 30),
            (7521, 'WARD',   'SALESMAN',7698,'1981-2-22', 1250,  500, 30),
            (7566, 'JONES',  'MANAGER', 7839,'1981-4-2',  2975, NULL, 20),
            (7654, 'MARTIN', 'SALESMAN',7698,'1981-9-28', 1250, 1400, 30),
            (7698, 'BLAKE',  'MANAGER',7839,'1981-5-1',  2850, NULL, 30)