在 postgres 中创建临时 table
Creation of a temporary table in postgres
我正在尝试在 Postgres 中创建一个临时 table(以加快加入速度,因为在整个会话中会有很多类似的查询)。将在会话开始时调用的 SQL 如下:
CREATE TEMPORARY TABLE extended_point AS
SELECT (
point.id,
local_location,
relative_location,
long_lat,
region,
dataset,
region.name,
region.sub_name,
color,
type)
FROM point, region, dataset
WHERE point.region = region.id AND region.dataset = dataset.id;
tables 点有 id::int、region::int、local_location::point、relative_location::point、long_lat:point 列(经度、纬度) .
区域有 id::int、color::int、dataset::int、name::varchar、sub_name::varchar 列。
数据集包含列 id::int、name::varchar、type:varchar。
当这是 运行 时,我收到错误消息:[25P02] 错误:当前事务中止,命令被忽略,直到事务块结束。
另一方面,命令在 PyCharm 中执行,并且是 Python 项目的一部分。
有什么建议吗?
提前致谢:)
这两个查询之间有一个重要的区别:
select 1, 'abc';
select (1, 'abc');
第一个查询 returns 一行 两 列的值为 1 和 'abc'。第二个 returns 一行 one 伪类型 record 列,值为 (1, 'abc')。
您的查询试图创建一个 table,其中包含一列伪类型 记录 。这是不可能的,应该以
结束
ERROR: column "row" has pseudo-type record
SQL state: 42P16
只需从您的查询中删除括号即可。
正如 a_horse 所述,[25P02] ERROR 不适用于相关查询。
顺便说一句,我的建议是:永远不要使用关键字作为 table/column 名称。
我正在尝试在 Postgres 中创建一个临时 table(以加快加入速度,因为在整个会话中会有很多类似的查询)。将在会话开始时调用的 SQL 如下:
CREATE TEMPORARY TABLE extended_point AS
SELECT (
point.id,
local_location,
relative_location,
long_lat,
region,
dataset,
region.name,
region.sub_name,
color,
type)
FROM point, region, dataset
WHERE point.region = region.id AND region.dataset = dataset.id;
tables 点有 id::int、region::int、local_location::point、relative_location::point、long_lat:point 列(经度、纬度) .
区域有 id::int、color::int、dataset::int、name::varchar、sub_name::varchar 列。
数据集包含列 id::int、name::varchar、type:varchar。
当这是 运行 时,我收到错误消息:[25P02] 错误:当前事务中止,命令被忽略,直到事务块结束。
另一方面,命令在 PyCharm 中执行,并且是 Python 项目的一部分。
有什么建议吗?
提前致谢:)
这两个查询之间有一个重要的区别:
select 1, 'abc';
select (1, 'abc');
第一个查询 returns 一行 两 列的值为 1 和 'abc'。第二个 returns 一行 one 伪类型 record 列,值为 (1, 'abc')。
您的查询试图创建一个 table,其中包含一列伪类型 记录 。这是不可能的,应该以
结束ERROR: column "row" has pseudo-type record
SQL state: 42P16
只需从您的查询中删除括号即可。 正如 a_horse 所述,[25P02] ERROR 不适用于相关查询。
顺便说一句,我的建议是:永远不要使用关键字作为 table/column 名称。