为什么我的 table 不是在 Postgres 中创建的?
Why isn't my table being created in Postgres?
我的最终目标是完成一个需要使用临时 table 的 Postgresql 函数。由于语法错误,尝试创建临时 table 本身无效。我很确定我的语法正确所以有人可以告诉我我在这里做错了什么吗?
在 PGAdmin III 中,我打开一个查询 window 并输入以下内容:
create temporary table tmp_parts
(
id serial not null,
part_number character varying(255) not null,
max_price numeric(19,2) not null
);
当我 运行 解释查询功能测试语法时,出现以下错误:
ERROR: syntax error at or near "serial"
LINE 3: id serial not null,
^
********** Error **********
ERROR: syntax error at or near "serial"
SQL state: 42601
Character: 98
我做错了什么?
serial
实际上不是 postgres 中的类型,它是
的 shorthand
id integer NOT NULL DEFAULT nextval('tmp_parts_seq')
我的 'guess' 要么它不喜欢 NOT NULL
的重复,要么(更有可能?)你不能有一个临时数字序列,因为它们是临时的。
比我们想象的要简单:
This previous question 显示语法,您需要删除括号并以分号结束语句。
您不能在 explain
中使用 create table
。只允许 following:
Any SELECT, INSERT, UPDATE, DELETE, VALUES, EXECUTE, DECLARE, or
CREATE TABLE AS statement, whose execution plan you wish to see.
我的最终目标是完成一个需要使用临时 table 的 Postgresql 函数。由于语法错误,尝试创建临时 table 本身无效。我很确定我的语法正确所以有人可以告诉我我在这里做错了什么吗?
在 PGAdmin III 中,我打开一个查询 window 并输入以下内容:
create temporary table tmp_parts
(
id serial not null,
part_number character varying(255) not null,
max_price numeric(19,2) not null
);
当我 运行 解释查询功能测试语法时,出现以下错误:
ERROR: syntax error at or near "serial"
LINE 3: id serial not null,
^
********** Error **********
ERROR: syntax error at or near "serial"
SQL state: 42601
Character: 98
我做错了什么?
serial
实际上不是 postgres 中的类型,它是
id integer NOT NULL DEFAULT nextval('tmp_parts_seq')
我的 'guess' 要么它不喜欢 NOT NULL
的重复,要么(更有可能?)你不能有一个临时数字序列,因为它们是临时的。
比我们想象的要简单:
This previous question 显示语法,您需要删除括号并以分号结束语句。
您不能在 explain
中使用 create table
。只允许 following:
Any SELECT, INSERT, UPDATE, DELETE, VALUES, EXECUTE, DECLARE, or CREATE TABLE AS statement, whose execution plan you wish to see.