View detail log and change permission to 0600. It work with me
DETAIL: File must have permissions u=rw (0600) or less if owned by the database user, or permissions u=rw,g=r (0640) or less if owned by root.
A more dynamic approach would be
, getting the lowest Number and the highest and building the m missing from there.
If you don't have a leading 2 like in the example 2006004 you need to pad the generated part
CREATE TABLE documents (
INSERT INTO documents
One easy way is to generate a list of all potential documentnos and remove from that all the ones that exist:
select 'YD4BC' || generate_series(2006004, 2006015) as missing_documentno
select documentno from documents;
To solve your issue, I did the following (a fiddle for all code below is available here):
A couple of points:
This solution makes use of the LAG() window function.
Window functions are very powerful and will repay any effort spent learning them many times over.
And finally, PostgreSQL 9.5 is no longer supported - you might be better off moving to a ...
Without CTEs and window functions:
SELECT colony, MIN(date_in) date_in, date_out
FROM ( SELECT t1.colony, t1.date_check date_in, MAX(t2.date_check) date_out
FROM test t1
JOIN test t2 ON t1.colony = t2.colony
AND t1.date_check < t2.date_check
AND t1.protection = 'Y'
AND t2.protection = '...
A correlated subquery against a VALUES table should do the trick:
t.A, t.B, t.C,
(SELECT COUNT(DISTINCT v.n) FROM (VALUES(t.A),(t.B),(t.C)) AS v(n)) AS cnt
FROM table t
If you wanted separate calculations on the values such as both counting and summing, you could use a lateral join (a.k.a APPLY) over VALUES instead:
SELECT A, B, C ,D, E, v....