[MonetDB-users] Problem with YEAR, MONTH, DAY functions

Fabian Groffen Fabian.Groffen at cwi.nl
Thu Oct 20 08:28:01 CEST 2011


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)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 487 bytes
Desc: Digital signature
URL: <http://www.monetdb.org/pipermail/users-list/attachments/20111020/13a1c83c/attachment.sig>


More information about the users-list mailing list