plpgsql

How do I iterate a table according to fixed time intervals in Postgres?

那年仲夏 提交于 2020-12-15 05:26:17
问题 I want to obtain all rows for which, every interval of 48h in a given period of time, are satisfied the following conditions. Every time all of them are true, I put a flag with value 1 for it. This is what I did so far. DO $$ DECLARE i record; CHARTTIME TIMESTAMP; BEGIN FOR i IN SELECT * FROM schema.lab L JOIN schema.icu I ON L.ID = I.ID WHERE L.ITEM = 50912 AND L.CHARTTIME < I.INTIME AND L.CHARTTIME > (I.INTIME - INTERVAL '7 DAY') LOOP CHARTTIME := L.CHARTTIME; FOREACH CHARTTIME IN ARRAY

Postgres equivalent to Oracle's “DIRECTORY” objects

自古美人都是妖i 提交于 2020-12-14 05:01:11
问题 Is it possible to create "DIRECTORY" object in Postgres? If not can some help me with a solution how implement it on PostgreSQL. 回答1: Not the best option, but you could use: COPY (select 1) TO PROGRAM 'mkdir --mode=777 -p /path/to/your/directory/' Note that only the last part of directory get the permissions set in mode. 回答2: The question doesn't even make sense really. PostgreSQL is a database management system . It doesn't have files and directories. The closest parallel I can think of is

Postgres return a default value when a column doesn't exist

浪子不回头ぞ 提交于 2020-12-08 05:37:54
问题 I have a query where I essentially want a fallback value if a certain column is missing. I was wondering if I can handle this purely in my query (rather than probing first and sending a seperate query. In essence i'm looking for an equivalent to COALESCE that handles the case of a missing column. Imagine the following 2 tables. T1 id | title | extra 1 A | value - and - T2 id | title 1 A I'd like to be able to SELECT from either of these tables WITH THE SAME QUERY. eg, if t2 actually had an