Skip to content

ERROR: ORDER/GROUP BY expression not found in targetlist #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
taleykoandrey opened this issue Apr 18, 2017 · 4 comments
Closed

ERROR: ORDER/GROUP BY expression not found in targetlist #84

taleykoandrey opened this issue Apr 18, 2017 · 4 comments
Assignees
Labels
Milestone

Comments

@taleykoandrey
Copy link

taleykoandrey commented Apr 18, 2017

Здравствуйте!

При выполнении функций, в теле которых имеется запрос с группировкой,
получаю ошибку.

ERROR: ORDER/GROUP BY expression not found in targetlist
CONTEXT: SQL statement "SELECT client_guid AS out_client_guid
FROM Receipts
WHERE payment_date BETWEEN in_date_begin AND in_date_end + interval '1 day'
AND total > 0
GROUP BY client_guid

Ошибка возникает не при первом, а, как правило, при 5-6 вызове функции
Если сделать запрос динамическим - ошибка не возникает.

@funbringer
Copy link
Collaborator

Добрый день, @taleykoandrey! Спасибо за баг-репорт.

Ошибка возникает не при первом, а, как правило, при 5-6 вызове функции.

Видимо, это связано с prepared statements. Вы не могли бы сформировать небольшой тест-кейс (схема таблицы + запрос + партицирование) для воспроизведения проблемы? Это значительно ускорит поиск решения.

@funbringer funbringer added the bug label Apr 18, 2017
@taleykoandrey
Copy link
Author

CREATE TABLE Receipts (
id TEXT NOT NULL,
total BIGINT,
payment_date TIMESTAMP WITHOUT TIME ZONE NOT NULL,
card_number TEXT,
client_guid BIGINT,
shop_number INTEGER,
cash_number INTEGER,
shift_number INTEGER,
receipt_number INTEGER,
CONSTRAINT receipts_pkey PRIMARY KEY(id)
)
WITH (oids = false);

CREATE INDEX receipts_receipts_payment_date_idx ON Receipts
USING btree (payment_date);

SELECT create_range_partitions('Receipts',
'payment_date',
'2015-01-01'::date,
'1 month' ::interval,
1);

CREATE OR REPLACE FUNCTION get_segment_by_date_avg_total (
in_date_begin date,
in_date_end date,
in_avg_min bigint,
in_avg_max bigint
)
RETURNS SETOF bigint AS
$body$
BEGIN

RETURN QUERY
SELECT client_guid
FROM Receipts
WHERE payment_date between in_date_begin and in_date_end
GROUP BY client_guid
HAVING sum(total)/count() BETWEEN in_avg_min AND in_avg_max
AND count(
) > 0;

END;
$body$
LANGUAGE 'plpgsql'
VOLATILE
CALLED ON NULL INPUT
SECURITY DEFINER
COST 100 ROWS 1000;

select get_segment_by_date_avg_total('2017-02-01', '2017-02-01', 1, 10000);
null
ещё 5 вызовов
и, наконец,
select get_segment_by_date_avg_total('2017-02-01', '2017-02-01', 1, 10000);

ERROR: ORDER/GROUP BY expression not found in targetlist
CONTEXT: SQL statement "SELECT client_guid
FROM Receipts
WHERE payment_date between in_date_begin and in_date_end
GROUP BY client_guid
HAVING sum(total)/count() BETWEEN in_avg_min AND in_avg_max
AND count(
) > 0"
PL/pgSQL function get_segment_by_date_avg_total(date,date,bigint,bigint) line 4 at RETURN QUERY

@funbringer
Copy link
Collaborator

to @taleykoandrey:

Спасибо, я смог воспроизвести проблему на master. Хорошая новость заключается в том, что эту проблему мы уже решили в текущей dev-ветке. Совсем скоро мы собираемся выпустить релиз 1.4.

@funbringer funbringer self-assigned this Apr 19, 2017
@funbringer funbringer added this to the Release 1.4 milestone Apr 19, 2017
@funbringer
Copy link
Collaborator

Исправлено в версии 1.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants