Reputation: 177
I have a problem with PostgreSQL to_date()
function, in my code mentioned bellow I get syntax error but can't find where.
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);
It says that syntax error is near "2014". Anyone knows where is the problem?
Upvotes: 1
Views: 2270
Reputation: 180927
You're trying to use unescaped single quotes '
inside a single quoted string. If you need to add a single quote inside a string, it needs to be doubled, as in ''
;
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',
...
Upvotes: 3