使用PostgreSQL 9.3,我想将计算值转换为数据类型float.

我的第一次try :

SELECT float(SUM(Seconds))/-1323 AS Averag;

给了我这个错误:

syntax error at or near "SUM"

我的第二次try :

SELECT to_float(SUM(Seconds))/-1323 AS Averag;

给了我这个错误:

 function to_float(bigint) does not exist

推荐答案

您需要使用cast语法:

SELECT CAST (SUM(Seconds) AS FLOAT)/-1323 AS Averag;

Postgresql相关问答推荐

如何生成给定大小且填充一个字段的数组?

PostgreSQL 不删除旧的 WAL 档案

Postgres:一次插入多行时自定义upsert(存储过程?)?

如何将特定值排序为最后,其余记录按 id DESC 排序?

有没有办法共享数据或监控复杂 PostgresQL 事务的进度?

AGE Graph 实际上存储为 postgreSQL 表,对吧?如何检索该表(不是图表)?

PostgreSQL 输入结束时的语法错误

DbProviderFactory 与 Npgsql?

PostgreSQL 在 mySQL 中的 date_trunc

无法向 postgresql 数据库授予用户权限(对于 rails 应用程序)

Flask-SQLAlchemy db.session.query(Model) 与 Model.query

PostgreSQL 中的 JSON 外键

如何在可选参数上查询 postgres?

我不明白 postgresql 的 nextval() 是如何工作的,有人可以解释一下吗?

使用 pg_dump 和 psql -U postgres db_name < ... 移动数据库会导致ERROR: relation "table_name" does not exist

SqlAlchemy:多列的不同计数

获取json列键为空的记录

PGAdmin 编辑数据

PostgreSQL 使用 UUID 与文本作为主键

使用 SQLAlchemy 进行 PostgreSQL ILIKE 查询