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