小编Ale*_*son的帖子

如何从 PostgreSQL 中获取当前数据库的名称?

\c <database_name>在 PostgreSQL 中使用将连接到指定的数据库。

如何确定当前数据库的名称?

进入:

my_db> current_database();
Run Code Online (Sandbox Code Playgroud)

产生:

ERROR:  syntax error at or near "current_database"
LINE 1: current_database();
Run Code Online (Sandbox Code Playgroud)

postgresql psql

143
推荐指数
4
解决办法
18万
查看次数

如何在相邻列中显示单独表的查询?

我有两个表 - 一个标题为“计划约束”的表,其中包含“sot_allowed”时间间隔,另一个标题为“计划”,其中包含“sot_contribution”时间间隔。

以下是两个表的架构(为便于阅读而进行了编辑):

                         Table "public.planning_constraints"
   Column    |           Type           |          Modifiers  
-------------+--------------------------+-------------------------------
 start_time  | timestamp with time zone | 
 end_time    | timestamp with time zone | 
 sot_allowed | interval                 | 

                         Table "public.planning"
      Column      |           Type           |         Modifiers          
------------------+--------------------------+----------------------------
 start_time       | timestamp with time zone | 
 end_time         | timestamp with time zone | 
 sot_contribution | interval                 | 
Run Code Online (Sandbox Code Playgroud)

我可以分别查询它们并生成我想要的总数。“planning_constraints”表的查询是:

SELECT
  date_trunc('day', start_time - INTERVAL '18 hours')::date AS planning_day,
  sum(sot_allowed) AS minutes_allowed
FROM planning_constraints
WHERE start_time>='2016-11-26 18:00:00+00' AND start_time<'2016-12-03 18:00:00+00' AND comment like …
Run Code Online (Sandbox Code Playgroud)

postgresql join datetime sum coalesce

5
推荐指数
1
解决办法
108
查看次数

标签 统计

postgresql ×2

coalesce ×1

datetime ×1

join ×1

psql ×1

sum ×1