学生写了一个文本文件2.txt,意图是在hm2库中创建一个receipt表,下面他的内容:
use hm2;CREATE TABLE receipt
(
ab_id serial NOT NULL,
CONSTRAINT receipt_pkey PRIMARY KEY (ab_id)
)
WITH (
OIDS=FALSE
);
ALTER TABLE receipt OWNER TO hm2;然后使用psql -f 2.txt 来调用它,结果出现如下错误:
psql:2.txt:14: ERROR: syntax error at or near "use"
第1行use hm2ant5
^请问什么原因?该如何使用sql给指定的库中建表?
use hm2;CREATE TABLE receipt
(
ab_id serial NOT NULL,
CONSTRAINT receipt_pkey PRIMARY KEY (ab_id)
)
WITH (
OIDS=FALSE
);
ALTER TABLE receipt OWNER TO hm2;然后使用psql -f 2.txt 来调用它,结果出现如下错误:
psql:2.txt:14: ERROR: syntax error at or near "use"
第1行use hm2ant5
^请问什么原因?该如何使用sql给指定的库中建表?
psql:2.txt:12: ERROR: schema "hm2" does not exist
ALTER TABLE
所以没有 use xxx 语句.
psql -f 2.txt hm2如果没有数据库名称,默认是postgres数据库
\c hm2ant5
切换数据库。
\c hm2;CREATE TABLE receipt
(
ab_id serial NOT NULL,
CONSTRAINT receipt_pkey PRIMARY KEY (ab_id)
)
WITH (
OIDS=FALSE
);
ALTER TABLE receipt OWNER TO hm2;