Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PostgreSQL:创建生成的列_Postgresql_Calculated Columns - Fatal编程技术网

PostgreSQL:创建生成的列

PostgreSQL:创建生成的列,postgresql,calculated-columns,Postgresql,Calculated Columns,目标: 我的目标是创建一个名为paymentPrice的新列,它是receiptPrice、platformFee、deliverederfee的总和(需要显示当前值的总和) 通过阅读文档,我认为使用生成的列将是实现这一目标的最佳方式 语法: ALTER TABLE "orders" ADD "paymentPrice" FLOAT GENERATED ALWAYS AS (orders."receiptPrice" + orders."platformFee" + orders."

目标:

我的目标是创建一个名为
paymentPrice
的新列,它是
receiptPrice
platformFee
deliverederfee
的总和(需要显示当前值的总和)

通过阅读文档,我认为使用生成的列将是实现这一目标的最佳方式

语法:

ALTER TABLE
   "orders"
ADD
   "paymentPrice" FLOAT GENERATED ALWAYS AS (orders."receiptPrice" + orders."platformFee" + orders."delivererFee") VIRTUAL;'
错误:

ALTER TABLE
   "orders"
ADD
   "paymentPrice" FLOAT GENERATED ALWAYS AS (orders."receiptPrice" + orders."platformFee" + orders."delivererFee") VIRTUAL;'
我当前的语法导致以下错误,但我无法找出我做错了什么

error: syntax error at or near "("

如上所述,评论生成栏将在Postgres 12中提供

在版本<12:1中,可以使用函数伪造生成的列:


我想,如果其他工具依赖于它(我使用的是类似工具的用例),或者如果查询应该不那么详细,那么这将是一个用例。

始终作为标识生成(…
。请参阅此处的文档,该文档目前在Postgres中不可用-计算列将在2019年第4季度发布的Postgres 12中可用,目前我只需创建一个视图-为什么需要该视图作为生成列?
SELECT paymentPrice(orders) FROM orders;