Postgres功能错误:列' t001'不存在

时间:2014-04-28 05:35:03

标签: postgresql

这是我的代码:

-- Team --
    DROP TABLE IF EXISTS team;
    CREATE TABLE team (
     tid      char(4) not null,
     name     varchar(20),
     city     varchar(25),
     headcoach varchar(12),
    primary key(tid)
    );

-- Players--
    DROP TABLE IF EXISTS players;
    CREATE TABLE players (
     pid     char(4) not null,
     players varchar (9),
     name    varchar(15),
     priceUSD  numeric(8,0),
     position varchar(2),
    primary key(pid)
    );        

-- Equipment --
    DROP TABLE IF EXISTS equipment;
    CREATE TABLE equipment (
     eid      char(4) not null,
     item     varchar(18),
     priceUSD numeric(10,0),
    primary key(eid)
    );

-- Team Equipment --
    DROP TABLE IF EXISTS teamequipment;
    CREATE TABLE teamequipment (
     tid      char(4) not null,
     eid    char(4),
     qty     integer, 
     priceUSD numeric(10,0),
    primary key(tid)
    );


-- Team--
    INSERT INTO team( tid, name, city, headcoach )
     VALUES('t001', 'Giants', 'New York', 'Coughlin');

    INSERT INTO team( tid, name, city, headcoach )
     VALUES('t002', 'Jets', 'New York', 'Ryan');

    INSERT INTO team( tid, name, city, headcoach )
     VALUES('t003', 'Patriots', 'Boston', 'Belichick');

    INSERT INTO team( tid, name, city, headcoach )
     VALUES('t004', 'Steelers', 'Pittsburgh', 'Tomlin');

    INSERT INTO team( tid, name, city, headcoach )
     VALUES('t005', 'Dolphins', 'Miami', 'Philbin');

    INSERT INTO team( tid, name, city, headcoach )
     VALUES('t006', 'Panthers', 'Charlotte', 'Rivera');

-- Players--
    INSERT INTO players( pid, players, name, priceUSD, position )
     VALUES('p001', 'Manning', 'Giants', 10000000.00, 'QB' );

    INSERT INTO players( pid, players, name, priceUSD, position )
     VALUES('p002', 'Cruz', 'Giants', 5000000.00, 'WR' );

    INSERT INTO players( pid, players, name, priceUSD, position )
     VALUES('p003', 'Smith', 'Jets', 3000000.00, 'QB' );

    INSERT INTO players( pid, players, name, priceUSD, position )
     VALUES('p004', 'Pace', 'Jets', 6000000.00, 'LB' );

    INSERT INTO players( pid, players, name, priceUSD, position )
     VALUES('p005', 'Brady', 'Patriots', 12000000.00, 'QB' );

    INSERT INTO players( pid, players, name, priceUSD, position )
     VALUES('p006', 'Ridley', 'Patriots', 5000000.00, 'RB' );

    INSERT INTO players( pid, players, name, priceUSD, position )
     VALUES('p007', 'Polamalu', 'Steelers', 7000000.00, 'SS' );

    INSERT INTO players( pid, players, name, priceUSD, position )
     VALUES('p008', 'Miller', 'Steelers', 4000000.00, 'TE' );

    INSERT INTO players( pid, players, name, priceUSD, position )
     VALUES('p009', 'Pouncey', 'Dolphins', 6000000.00, 'C' );

    INSERT INTO players( pid, players, name, priceUSD, position )
     VALUES('p010', 'Wake', 'Dolphins', 11000000.00, 'DE' );

    INSERT INTO players( pid, players, name, priceUSD, position )
     VALUES('p011', 'Newton', 'Panthers', 9000000.00, 'QB' );

    INSERT INTO players( pid, players, name, priceUSD, position )
     VALUES('p012', 'Hardy', 'Panthers', 13000000.00, 'DE' );



-- Equipment 


    INSERT INTO equipment ( eid, item, priceUSD)
     VALUES('e01', 'shoulder pads', 225.00 );

    INSERT INTO equipment ( eid, item, priceUSD)
     VALUES('e02', 'gloves', 40.00 );
    INSERT INTO equipment ( eid, item, priceUSD)
     VALUES('e03', 'cleats', 115.00 );

    INSERT INTO equipment ( eid, item, priceUSD)
     VALUES('e04', 'helmets', 300.00 );

    INSERT INTO equipment ( eid, item, priceUSD)
     VALUES('e05', 'socks', 10.00 );

    INSERT INTO equipment ( eid, item, priceUSD)
     VALUES('e06', 'knee pads', 6.00 );

    INSERT INTO equipment ( eid, item, priceUSD)
     VALUES('e07', 'jerseys', 150.00);

    INSERT INTO equipment ( eid, item, priceUSD)
     VALUES('e08', 'visors', 50.00 );

    INSERT INTO equipment ( eid, item, priceUSD)
     VALUES('e09', 'pants', 30.00 );


-- Team Equipment


    INSERT INTO teamequipment ( tid, eid, qty, priceUSD)
     VALUES(t001, e01, 25, 5625.00);

    INSERT INTO teamequipment( tid, eid, qty, priceUSD)
     VALUES(t001, e04, 33, 9900.00);

    INSERT INTO teamequipment( tid, eid, qty, priceUSD)
     VALUES(t001, e08, 15, 750.00);

    INSERT INTO teamequipment( tid, eid, qty, priceUSD)
     VALUES(t002, e01, 37, 8325.00);

    INSERT INTO teamequipment( tid, eid, qty, priceUSD)
     VALUES(t002, e02, 45, 1800.00);

    INSERT INTO teamequipment( tid, eid, qty, priceUSD)
     VALUES(t002, e04, 20, 6000.00);

    INSERT INTO teamequipment( tid, eid, qty, priceUSD)
     VALUES(t002, e07, 55, 8250.00);

    INSERT INTO teamequipment( tid, eid, qty, priceUSD)
     VALUES(t003, e01, 10, 2250.00);

    INSERT INTO teamequipment( tid, eid, qty, priceUSD)
     VALUES(t003, e03, 25, 2875.00);

    INSERT INTO teamequipment( tid, eid, qty, priceUSD)
     VALUES(t004, e05, 50, 500.00);

    INSERT INTO teamequipment( tid, eid, qty, priceUSD)
     VALUES(t004, e07, 55, 8250.00);

    INSERT INTO teamequipment( tid, eid, qty, priceUSD)
     VALUES(t004, e09, 11, 330.00);

    INSERT INTO teamequipment( tid, eid, qty, priceUSD)
     VALUES(t005, e01, 22, 4950.00);

    INSERT INTO teamequipment( tid, eid, qty, priceUSD)
     VALUES(t005, e06, 40, 240.00);

    INSERT INTO teamequipment( tid, eid, qty, priceUSD)
     VALUES(t005, e08, 20, 1000.00);

    INSERT INTO teamequipment( tid, eid, qty, priceUSD)
     VALUES(t006, e02, 13, 520.00);

    INSERT INTO teamequipment( tid, eid, qty, priceUSD)
     VALUES(t006, e05, 15, 150.00);

    INSERT INTO teamequipment( tid, eid, qty, priceUSD)
     VALUES(t006, e08, 3, 150.00);

我得到的错误是:

****** 错误 ******

ERROR: column "t001" does not exist
SQL state: 42703
Character: 3637

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:0)

字符变化 char 值必须位于单引号中。 如下更改您的查询:

INSERT INTO teamequipment( tid, eid, qty, priceUSD) VALUES('t001', 'e04', 33, 9900.00);

答案 1 :(得分:0)

使用t00x插入使用引号时,例如' t001'。您已将该列声明为char(4)。