-
-
Notifications
You must be signed in to change notification settings - Fork 568
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
Postgraphile computed column fails with tsrange and additional parameters #1987
Comments
More complete schema: drop schema if exists space cascade;
create schema space;
CREATE TYPE space.pad_type AS ENUM('MOBILE', 'STATIC', 'TEMPORARY');
CREATE TYPE space.launch_pad AS (id BIGINT, type space.pad_type);
-- DROP TABLE IF EXISTS space.mobile_pad;
CREATE TABLE space.mobile_pad (
id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"name" TEXT NOT NULL,
time_to_reach_in_hours NUMERIC DEFAULT 10
);
-- DROP TABLE IF EXISTS space.static_pad;
CREATE TABLE space.static_pad (
id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"name" TEXT NOT NULL,
time_to_reach_in_hours NUMERIC DEFAULT 5
);
-- DROP TABLE IF EXISTS space.temp_pad;
create TABLE space.temp_pad (
id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"name" TEXT NOT NULL,
time_to_reach_in_hours NUMERIC DEFAULT 15
);
-- DROP TABLE IF EXISTS space.spacecraft;
CREATE TABLE IF NOT EXISTS space.spacecraft (
id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"name" TEXT NOT NULL,
return_to_earth TSRANGE NOT NULL
);
-- DROP FUNCTION space.spacecraft_eta;
CREATE OR REPLACE FUNCTION space.spacecraft_eta(
spacecraft space.spacecraft,
"to" space.launch_pad
) RETURNS TSRANGE LANGUAGE plpgsql STABLE
AS $$
BEGIN
RETURN $1.return_to_earth;
END $$;
insert into space.mobile_pad(name) select i::text from generate_series(1, 10) i;
insert into space.static_pad(name) select i::text from generate_series(1, 10) i;
insert into space.temp_pad(name) select i::text from generate_series(1, 10) i;
insert into space.spacecraft(name, return_to_earth) select i::text, tsrange((date_trunc('day', now()) - (i+1) * interval '1 day')::timestamp, (date_trunc('day', now()) - (i) * interval '1 day')::timestamp, '[)') from generate_series(1, 10) i; |
Well ain't this just a spanner in the works 😭 |
It seems that we're calling this database function separately rather than inlining it, for some reason. Reason unknown at this time, but it's somewhat irrelevant to the issue (although if we were inlining then it wouldn't be an issue in this case...) So we're pulling down the record as a string, and then we're using So... The whole Alternatively, the way that we do |
My gut says we should just remove An alternative might be to require And of course figuring out why this function isn't being inlined in the first place would also help. |
|
This is now fixed on Please note that this next release will be a big one, including the work on #2013 (which I was meant to be working on today 😅), so it's unlikely to go out in the next couple of weeks. |
Thank you for your reactivity, that was way faster than I could've imagined 👌 |
Summary
When using the
computed columns
there is a strange behavior with the additional parameters and the typetsrange
from postgres.Note that the errors do not show when testing the functions directly against the database but it only appears when running the graphql queries.
The following code snippets comes from the migrations in the
flyway
folder.In this code snippet, you can see that we have a custom type
to space.launch_pad
as a second parameter. Even if it's not used it's not the problem here.When running the following query, you can see that the eta column will be incorrect.
Note that it's note the same error we face depending on the tsrange value.
A value like:
["2024-03-21 00:00:00","2024-03-22 23:59:59"]
where[]
would take the upper bound and set is as the lower bound of the resultA value like:
["2024-03-20 00:00:00","2024-03-23 00:00:00")
where[)
would completely failRunning the exact same query without the parameter works fine
The probleme seems to appears when using a "custom type" as a parameter.
Steps to reproduce
I've added a complete reproduction repo for this case.
But basically this running this would be enough to reproduce.
Expected results
Works as expected
Actual results
A value like:
["2024-03-21 00:00:00","2024-03-22 23:59:59"]
where[]
would take the upper bound and set is as the lower bound of the resultA value like:
["2024-03-20 00:00:00","2024-03-23 00:00:00")
where[)
would completely failAdditional context
https://github.com/MartinPELCAT/postgraphile-debug
The text was updated successfully, but these errors were encountered: