Use Static Numeric and Floating-Point Values in GraphQL
Use floating-point values in QBE predicates and project static numeric values in GRAPHQL() table-function responses.
The GRAPHQL() table function supports floating-point numeric values in QBE predicates. You can also project static numeric field values in the response.
Create the Lap Time Table
The following example creates the lap_time table and inserts lap-time data:
CREATE TABLE lap_time
(lap_time_id INTEGER PRIMARY KEY,
driver_id INTEGER NOT NULL,
circuit VARCHAR2(255) NOT NULL,
lap_seconds NUMBER(6,3) NOT NULL,
CONSTRAINT lap_time_driver_fk FOREIGN KEY(driver_id) REFERENCES driver(driver_id));
INSERT INTO lap_time (lap_time_id, driver_id, circuit, lap_seconds) VALUES
(1, 101, 'Silverstone', 87.456),
(2, 105, 'Silverstone', 86.912),
(3, 102, 'Monza', 81.375),
(4, 103, 'Monza', 81.902);
Use a Floating-Point Value in a QBE Predicate
The following example uses the floating-point value 87.000 in a QBE predicate:
SELECT JSON_SERIALIZE(data PRETTY) AS data FROM GRAPHQL('
query getFastLapTimes {
lap_time (
check: {
lap_seconds: {_lt: 87.000}
}
) {
lapTimeId: lap_time_id
circuit
lapSeconds: lap_seconds
driver @unnest {
driverName: name
}
}
}
');
The query returns lap times where lap_seconds is less than 87.000:
DATA
--------------------------------------------------------------------------------
{
"lapTimeId" : 2,
"circuit" : "Silverstone",
"lapSeconds" : 86.912,
"driverName" : "Max Verstappen"
}
{
"lapTimeId" : 3,
"circuit" : "Monza",
"lapSeconds" : 81.375,
"driverName" : "Oscar Piastri"
}
{
"lapTimeId" : 4,
"circuit" : "Monza",
"lapSeconds" : 81.902,
"driverName" : "Charles Leclerc"
}
3 rows selected.
Project Static Numeric Field Values
The following example projects the static numeric values 87.000 and 2024 in the response:
SELECT JSON_SERIALIZE(data PRETTY) AS data FROM GRAPHQL('
query {
lap_time (
check: {
lap_seconds: {_lt: 87.000}
}
) {
lapTimeId: lap_time_id
circuit
lapSeconds: lap_seconds
targetLapSeconds: 87.000
season: 2024
driver @unnest {
driverName: name
}
}
}
');
This query returns the same rows as the previous query and includes the static numeric fields targetLapSeconds and season.
DATA
--------------------------------------------------------------------------------
{
"lapTimeId" : 2,
"circuit" : "Silverstone",
"lapSeconds" : 86.912,
"targetLapSeconds" : 87.000,
"season" : 2024,
"driverName" : "Max Verstappen"
}
{
"lapTimeId" : 3,
"circuit" : "Monza",
"lapSeconds" : 81.375,
"targetLapSeconds" : 87.000,
"season" : 2024,
"driverName" : "Oscar Piastri"
}
{
"lapTimeId" : 4,
"circuit" : "Monza",
"lapSeconds" : 81.902,
"targetLapSeconds" : 87.000,
"season" : 2024,
"driverName" : "Charles Leclerc"
}
3 rows selected.