Reputation: 1867
i have following query.But TranDate,Amount,Balance are displaying Null. Am new to postgresql. But in sql server values are displaying
CREATE TEMP TABLE tran
(TranDate,Amount,Balance) AS
VALUES
('2019-01-01'::date, 1000::int,1000::int),
('2019-01-02', 2000,3000),
('2019-01-03', NULL,3000),
('2019-01-04', -500,2500);
SELECT tran.TranDate,tran.Amount,tran.Balance, date(d) as day
FROM generate_series(timestamp '2018-01-01'
, timestamp '2018-01-31'
, interval '1 day') d
left join tran ON date(tran.TranDate) = d
Upvotes: 1
Views: 89
Reputation: 1269443
If you run the code using overlapping date ranges, you will see results:
SELECT tran.TranDate, tran.Amount, tran.Balance, date(d) as day
FROM generate_series(timestamp '2019-01-01',
timestamp '2019-01-31',
interval '1 day'
) d left join
tran
ON date(tran.TranDate) = d ;
You can observe this in this db<>fiddle.
Upvotes: 1