![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi folks. I've got a table with three dates which are populated from an external source. I then want to have a view with two calculated dates in it, e.g. if date_1 is null and date_2 is null then date_a=NULL if date_1 is not null and date 2 is null then date_a=date_1+'90 days' if date_1 > date3 rhen date_b=date1 else date_b=date2 etc. What's the best way to do this? I know it's a quite open question but I'm interested to hear different responses -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pgsql-sql mailing list (pgsql-sql (AT) postgresql (DOT) org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql |
#3
| |||
| |||
|
|
I would define a function and use it to abstract the expected behavior. It would appear that there are several conditions so this abstraction would provide for both usability and maintainability. - Johnny |
#4
| |||
| |||
|
|
Hi folks. I've got a table with three dates which are populated from an external source. I then want to have a view with two calculated dates in it, e.g. if date_1 is null and date_2 is null then date_a=NULL if date_1 is not null and date 2 is null then date_a=date_1+'90 days' if date_1 > date3 rhen date_b=date1 else date_b=date2 etc. What's the best way to do this? |
|
I know it's a quite open question but I'm interested to hear different responses |
#5
| |||
| |||
|
|
What's the best way to do this? CASE looks good. I know it's a quite open question but I'm interested to hear different responses "date_b" on line three, is that a typo? if not how am i to interpret it? |
#6
| |||
| |||
|
|
CREATE OR REPLACE FUNCTION get_dates(date, date, date) RETURNS TABLE(date1 date, date2 date) AS $$ DECLARE date_1 DATE := NULL; date_2 DATE := NULL; BEGIN -- test your conditions here RETURN QUERY SELECT date_1::date, date_2::date; END; $$ LANGUAGE PLPGSQL; I hope this helps, Johnny |
![]() |
| Thread Tools | |
| Display Modes | |
| |