我对PostgreSQLto_date()函数有问题,在下面提到的代码中,我得到语法错误,但找不到位置。

SELECT * from crosstab('select upit, sat, count(*) as broj
                                from upiti
                                where datum >= to_date('26-10-2014','DD-MM-YYYY') AND datum <= to_date('29-10-2014','DD-MM-YYYY')
                                group by upit,sat
                                ORDER BY upit,sat',

'select rbrSat from sat order by rbrSat') as ct (upit text, s00 INT, s01 INT, s02 INT, s03 INT, s04 INT, s05 INT, s06 INT, s07 INT, s08 INT, s09 INT, s10 INT, s11 INT, s12 INT, s13 INT, s14 INT, s15 INT, s16 INT, s17 INT, s18 INT, s19 INT, s20 INT, s21 INT, s22 INT, s23 INT);

它说语法错误接近“2014”。有人知道问题出在哪里吗?

最佳答案

您试图在单引号字符串中使用未转义的单引号'。如果需要在字符串中添加单引号,则需要将其加倍,如''

SELECT * from crosstab('select upit, sat, count(*) as broj
                        from upiti
                        where datum >= to_date(''26-10-2014'',''DD-MM-YYYY'')
                          AND datum <= to_date(''29-10-2014'',''DD-MM-YYYY'')
                            group by upit,sat
                            ORDER BY upit,sat',

...

关于sql - PostgreSQL to_date(),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26574313/

10-15 21:25