Skip to content

Commit 214bb36

Browse files
authored
Merge pull request #585 from bradh/proj_ver_2025-05-26
feat: add PROJ version functions
2 parents e189d40 + 68b7fb7 commit 214bb36

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed

docs/functions.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
| [`ST_ZMFlag`](#st_zmflag) | Returns a flag indicating the presence of Z and M values in the input geometry. |
127127
| [`ST_ZMax`](#st_zmax) | Returns the maximum Z coordinate of a geometry |
128128
| [`ST_ZMin`](#st_zmin) | Returns the minimum Z coordinate of a geometry |
129+
| [`DuckDB_PROJ_Version`](#duckdb_proj_version) | Returns the current (runtime) version of the PROJ library. |
129130

130131
**[Aggregate Functions](#aggregate-functions)**
131132

@@ -2623,6 +2624,49 @@ SELECT ST_ZMin(ST_Point(1, 2, 3))
26232624

26242625
----
26252626

2627+
### DuckDB_PROJ_Version
2628+
2629+
2630+
#### Signature
2631+
2632+
```sql
2633+
VARCHAR DuckDB_PROJ_Version ()
2634+
```
2635+
2636+
#### Description
2637+
2638+
Returns runtime version of the supporting PROJ library.
2639+
2640+
#### Example
2641+
2642+
```sql
2643+
SELECT DuckDB_PROJ_Version()
2644+
```
2645+
2646+
----
2647+
2648+
2649+
### DuckDB_PROJ_Compiled_Version
2650+
2651+
2652+
#### Signature
2653+
2654+
```sql
2655+
VARCHAR DuckDB_PROJ_Compiled_Version ()
2656+
```
2657+
2658+
#### Description
2659+
2660+
Returns compile-time version of the supporting PROJ library.
2661+
2662+
#### Example
2663+
2664+
```sql
2665+
SELECT DuckDB_PROJ_Compiled_Version()
2666+
```
2667+
2668+
----
2669+
26262670
## Aggregate Functions
26272671

26282672
### ST_CoverageInvalidEdges_Agg

src/spatial/modules/proj/proj_module.cpp

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "duckdb/parser/parsed_data/create_table_function_info.hpp"
99
#include "duckdb/execution/expression_executor.hpp"
1010
#include "duckdb/planner/expression/bound_function_expression.hpp"
11+
#include "duckdb/main/extension_util.hpp"
1112

1213
#include "proj.h"
1314
#include "geodesic.h"
@@ -1102,6 +1103,88 @@ struct ST_DWithin_Spheroid {
11021103
}
11031104
};
11041105

1106+
struct DuckDB_Proj_Version {
1107+
1108+
static void Execute(DataChunk &args, ExpressionState &state, Vector &result) {
1109+
D_ASSERT(args.ColumnCount() == 0);
1110+
PJ_INFO pj_info = proj_info();
1111+
string_t version(pj_info.version);
1112+
auto val = Value(version);
1113+
result.Reference(val);
1114+
}
1115+
1116+
static constexpr auto DESCRIPTION = R"(
1117+
Returns a text description of the PROJ library version that is being used by this instance of DuckDB.
1118+
)";
1119+
1120+
static constexpr auto EXAMPLE = R"(
1121+
SELECT duckdb_proj_version();
1122+
┌───────────────────────┐
1123+
│ duckdb_proj_version() │
1124+
│ varchar │
1125+
├───────────────────────┤
1126+
│ 9.1.1 │
1127+
└───────────────────────┘
1128+
)";
1129+
1130+
static void Register(DatabaseInstance &db) {
1131+
FunctionBuilder::RegisterScalar(db, "DuckDB_Proj_Version", [](ScalarFunctionBuilder &func) {
1132+
func.AddVariant([](ScalarFunctionVariantBuilder &variant) {
1133+
variant.SetReturnType(LogicalType::VARCHAR);
1134+
1135+
variant.SetFunction(Execute);
1136+
});
1137+
1138+
func.SetExample(EXAMPLE);
1139+
func.SetDescription(DESCRIPTION);
1140+
1141+
func.SetTag("ext", "spatial");
1142+
func.SetTag("category", "meta");
1143+
});
1144+
}
1145+
};
1146+
1147+
1148+
struct DuckDB_Proj_Compiled_Version {
1149+
1150+
static void Execute(DataChunk &args, ExpressionState &state, Vector &result) {
1151+
D_ASSERT(args.ColumnCount() == 0);
1152+
string_t version(pj_release);
1153+
auto val = Value(version);
1154+
result.Reference(val);
1155+
}
1156+
1157+
static constexpr auto DESCRIPTION = R"(
1158+
Returns a text description of the PROJ library version that that this instance of DuckDB was compiled against.
1159+
)";
1160+
1161+
static constexpr auto EXAMPLE = R"(
1162+
SELECT duckdb_proj_compiled_version();
1163+
┌────────────────────────────────┐
1164+
│ duckdb_proj_compiled_version() │
1165+
│ varchar │
1166+
├────────────────────────────────┤
1167+
│ Rel. 9.1.1, December 1st, 2022 │
1168+
└────────────────────────────────┘
1169+
)";
1170+
1171+
static void Register(DatabaseInstance &db) {
1172+
FunctionBuilder::RegisterScalar(db, "DuckDB_PROJ_Compiled_Version", [](ScalarFunctionBuilder &func) {
1173+
func.AddVariant([](ScalarFunctionVariantBuilder &variant) {
1174+
variant.SetReturnType(LogicalType::VARCHAR);
1175+
1176+
variant.SetFunction(Execute);
1177+
});
1178+
1179+
func.SetExample(EXAMPLE);
1180+
func.SetDescription(DESCRIPTION);
1181+
1182+
func.SetTag("ext", "spatial");
1183+
func.SetTag("category", "meta");
1184+
});
1185+
}
1186+
};
1187+
11051188
} // namespace
11061189

11071190
//######################################################################################################################
@@ -1121,6 +1204,10 @@ void RegisterProjModule(DatabaseInstance &db) {
11211204
ST_Length_Spheroid::Register(db);
11221205
ST_Distance_Spheroid::Register(db);
11231206
ST_DWithin_Spheroid::Register(db);
1207+
1208+
// Meta functions for proj lib
1209+
DuckDB_Proj_Version::Register(db);
1210+
DuckDB_Proj_Compiled_Version::Register(db);
11241211
}
11251212

11261213
} // namespace duckdb

0 commit comments

Comments
 (0)