Skip to content

Commit b81454e

Browse files
feat: add empty pg_range table to pg_catalog
1 parent a4fb8b6 commit b81454e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

datafusion-postgres/src/pg_catalog.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const PG_CATALOG_TABLE_PG_NAMESPACE: &str = "pg_namespace";
2424
const PG_CATALOG_TABLE_PG_PROC: &str = "pg_proc";
2525
const PG_CATALOG_TABLE_PG_DATABASE: &str = "pg_database";
2626
const PG_CATALOG_TABLE_PG_AM: &str = "pg_am";
27+
const PG_CATALOG_TABLE_PG_RANGE: &str = "pg_range";
2728

2829
/// Determine PostgreSQL table type (relkind) from DataFusion TableProvider
2930
fn get_table_type(table: &Arc<dyn TableProvider>) -> &'static str {
@@ -64,6 +65,7 @@ pub const PG_CATALOG_TABLES: &[&str] = &[
6465
PG_CATALOG_TABLE_PG_PROC,
6566
PG_CATALOG_TABLE_PG_DATABASE,
6667
PG_CATALOG_TABLE_PG_AM,
68+
PG_CATALOG_TABLE_PG_RANGE,
6769
];
6870

6971
// Data structure to hold pg_type table data
@@ -249,6 +251,7 @@ impl SchemaProvider for PgCatalogSchemaProvider {
249251
)))
250252
}
251253
PG_CATALOG_TABLE_PG_PROC => Ok(Some(self.create_pg_proc_table())),
254+
PG_CATALOG_TABLE_PG_RANGE => Ok(Some(self.create_pg_range_table())),
252255
_ => Ok(None),
253256
}
254257
}
@@ -715,6 +718,25 @@ impl PgCatalogSchemaProvider {
715718
Arc::new(provider)
716719
}
717720

721+
/// Create a mock empty table for pg_range
722+
fn create_pg_range_table(&self) -> Arc<dyn TableProvider> {
723+
// Define the schema for pg_range
724+
// This matches PostgreSQL's pg_range table columns
725+
let schema = Arc::new(Schema::new(vec![
726+
Field::new("rngtypid", DataType::Int32, false), // OID of the range type
727+
Field::new("rngsubtype", DataType::Int32, false), // OID of the element type (subtype) of this range type
728+
Field::new("rngmultitypid", DataType::Int32, false), // OID of the multirange type for this range type
729+
Field::new("rngcollation", DataType::Int32, false), // OID of the collation used for range comparisons, or zero if none
730+
Field::new("rngsubopc", DataType::Int32, false), // OID of the subtype's operator class used for range comparisons
731+
Field::new("rngcanonical", DataType::Int32, false), // OID of the function to convert a range value into canonical form, or zero if none
732+
Field::new("rngsubdiff", DataType::Int32, false), // OID of the function to return the difference between two element values as double precision, or zero if none
733+
]));
734+
735+
// Create memory table with schema
736+
let provider = MemTable::try_new(schema, vec![]).unwrap();
737+
Arc::new(provider)
738+
}
739+
718740
/// Create a populated pg_proc table with standard PostgreSQL functions
719741
fn create_pg_proc_table(&self) -> Arc<dyn TableProvider> {
720742
// Define complete schema for pg_proc (matching PostgreSQL)

0 commit comments

Comments
 (0)