
On 20-10-2011 08:21:27 +0200, Stefan Manegold wrote:
Hi,
YEAR is also a keyworkd in SQL. To indicate that you want to use the function (identifier) YEAR, you need to wrap it in double quotes, e.g.,
sql>select year( '2002-03-21'); syntax error, unexpected YEAR in: "select year" sql>select "year"( '2002-03-21'); +-------------------+ | year_single_value | +===================+ | 2002 | +-------------------+ 1 tuple (1.735ms)
Alternative is using the EXTRACT function, which makes it a bit more verbose: sql>select extract(year from now()); +-------------------+ | current_timestamp | +===================+ | 2011 | +-------------------+ 1 tuple (11.830ms) sql>select extract(year from '2002-03-21'); +-------------------+ | year_single_value | +===================+ | 2002 | +-------------------+ 1 tuple (0.725ms)