将MS Access查询转换为PostgreSQL查询(format())

时间:2011-03-18 21:23:05

标签: sql ms-access postgresql

我有一个来自MS Access SQL的查询,我想在PostgreSQL中执行:

SELECT Format("start_date", 'mmmm') AS "Month", 
   DFS_FIRE_ARCHIVE.FIRE_YEAR AS "Year", 
   Count(DFS_FIRE_ARCHIVE.FIRE_ZONE) AS "Number of Fires", 
   OBJECTIVES_NFD."response_category"

FROM (DFS_FIRE_ARCHIVE 

INNER JOIN OBJECTIVE_ORDER ON DFS_FIRE_ARCHIVE.OBJECTIVE = OBJECTIVE_ORDER.OBJECTIVE) 
INNER JOIN OBJECTIVES_NFD ON OBJECTIVE_ORDER.OBJECTIVE = OBJECTIVES_NFD.OBJECTIVE

GROUP BY Format("start_date",'mmmm'), 
     DFS_FIRE_ARCHIVE.FIRE_YEAR, 
     DFS_FIRE_ARCHIVE.OBJECTIVE, 
     Format("start_date",'mm'), 
     OBJECTIVE_ORDER.ORDER, 
     DFS_FIRE_ARCHIVE.FIRE_MGT_ZONE, 
     DFS_FIRE_ARCHIVE.FIRE_TYPE, 
     OBJECTIVES_NFD."response_category"

HAVING (((DFS_FIRE_ARCHIVE.FIRE_YEAR)=2009) AND ((DFS_FIRE_ARCHIVE.FIRE_MGT_ZONE)='INT') AND ((DFS_FIRE_ARCHIVE.FIRE_TYPE)='IFR'))

ORDER BY Format("start_date",'mm'), OBJECTIVE_ORDER.ORDER, DFS_FIRE_ARCHIVE.OBJECTIVE;

The error I am receiving is:

    ERROR:  function format(timestamp without time zone, unknown) does not exist
LINE 1: SELECT Format("start_date", 'mmmm') AS "Month", 
               ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

任何帮助都将不胜感激,谢谢。

2 个答案:

答案 0 :(得分:1)

您应该替换Format的功能可能是to_char,例如to_char(timestamp, 'MM')

看一下PostgreSQL文档: http://www.postgresql.org/docs/9.0/static/functions-formatting.html

答案 1 :(得分:0)