On Tue, Mar 31, 2009 at 10:25 AM, Jhonny Velasquez c.
<[email protected]> wrote:
> puedo hacer esta consulta en postgres?
>
> son campos de tipo date, de los cuales quiero extaer el mes y año
> directamente en la consulta sql.
>

en lugar de la funcion month tienes que hacer:

extract(month from campo_fecha)

o bien puedes crear una serie de funciones del tipo (lo mismo para year):

CREATE FUNCTION month(timestamp without time zone) RETURNS integer
    AS $_$ select extract('month' from $1)::integer; $_$
    LANGUAGE sql STABLE;


CREATE FUNCTION month(timestamp with time zone) RETURNS integer
    AS $_$ select extract('month' from $1)::integer; $_$
    LANGUAGE sql STABLE;


CREATE FUNCTION month(date) RETURNS integer
    AS $_$ select extract('month' from $1)::integer; $_$
    LANGUAGE sql STABLE;


-- 
Atentamente,
Jaime Casanova
Soporte y capacitación de PostgreSQL
Asesoría y desarrollo de sistemas
Guayaquil - Ecuador
Cel. +59387171157
--
TIP 2: puedes desuscribirte de todas las listas simultáneamente
    (envía "unregister TuDirecciónDeCorreo" a [email protected])

Responder a