Ver Mensaje Individual
  #2 (permalink)  
Antiguo 02/10/2003, 13:41
Cote2004
 
Fecha de Ingreso: octubre-2003
Mensajes: 2
Antigüedad: 20 años, 7 meses
Puntos: 0
Hola, esto te puede servir:

create or replace function Day_Spa(timestamp)
Returns Text As
'Declare
Out_Day Text;
Num_Day SmallInt;
Begin
Select EXTRACT(DOW FROM $1)
Into Num_Day;

If Num_Day = 1 Then
Out_Day = ''LUNES'';
ElsIf Num_Day = 2 Then
Out_Day = ''MARTES'';
ElsIf Num_Day = 3 Then
Out_Day = ''MIERCOLES'';
ElsIf Num_Day = 4 Then
Out_Day = ''JUEVES'';
ElsIf Num_Day = 5 Then
Out_Day = ''VIERNES'';
ElsIf Num_Day = 6 Then
Out_Day = ''SABADO'';
Else Num_Day = 7 Then
Out_Day = ''DOMINGO'';
End If;

Return Out_Day;
End;
' LANGUAGE PLPGSQL;


La llamas como:

select Day_Spa(current_timestamp::timestamp);

Antes de crearla (desde psql copiar/pegar)
debes tener creado el lenguaje plpgsql.
Esto ultimo lo puedes hacer con:

$ createlang <nom_db> plpgsql

(obviamente como el usuario unix postgres)