При этому line иногда плавает.
поэтому проще будет найти файлы и все попереносить.
create index on tablename using btree(((features ->> 'capacity'::text)::integer));
Т.е. индекс используется, хотя в данном случае index срабатывает на price столбце? Тогда почему запрос отрабатывает быстро?
select day, data
from generate_series('2017-12-10', '2017-12-12', interval '1 day') as day,
lateral (
select data from tablename
where "timestamp" between day and day + interval '1 day'
order by "timestamp" desc limit 1
) ljd;
with recursive t as (
(select "timestamp"::date as day, data from tablename order by "timestamp" desc limit 1)
union all
select bpt.* from t, lateral (
select "timestamp"::date as day, data from tablename where "timestamp" < t.day order by "timestamp" desc limit 1
) as bpt
)
select * from t;
with
data (new_user_id, new_name) as (values(%(user_id)s, %(name)s)),
wr as (
INSERT INTO users(user_id, name)
select new_user_id, new_name from data
ON CONFLICT (user_id) DO NOTHING returning user_id
), upd as (
update users set name = new_name from data where users.user_id = data.new_user_id and data.new_user_id not in (
select user_id from wr
)
)
select count(*) from wr;
WITH new_tbl_main( id ) AS (
INSERT INTO tbl_main ( institution_id ) VALUES ( 38)
RETURNING id
), chi2 as (
INSERT INTO tbl_child1 ( tbl_main_id )
SELECT new_tbl_main.id FROM new_tbl_main
)
INSERT INTO tbl_child1 ( tbl_main_id )
SELECT new_tbl_main.id FROM new_tbl_main
RETURNING tbl_main_id
ERROR: cannot use RETURN QUERY in a non-SETOF function
CREATE OR REPLACE FUNCTION checkPermission(text, text) RETURNS BOOLEAN AS
$$
BEGIN
RETURN $1 && $2;
END;
$$ LANGUAGE plpgsql
CREATE OR REPLACE FUNCTION checkPermission(text, text) RETURNS BOOLEAN AS
$$
SELECT $1 && $2;
$$ LANGUAGE sql
Есть у постгреса оператор &&
select oprkind, l.typname, oprname, r.typname from pg_operator join pg_type l on oprleft = l.oid join pg_type r on oprright = r.oid where oprname = '&&';
oprkind | typname | oprname | typname
---------+-----------+---------+-----------
b | box | && | box
b | polygon | && | polygon
b | tinterval | && | tinterval
b | circle | && | circle
b | inet | && | inet
b | tsquery | && | tsquery
b | anyarray | && | anyarray
b | anyrange | && | anyrange