feat: reject unsupported foreign table column types at DDL time - #640
Open
sanskar-soni-9 wants to merge 1 commit into
Open
feat: reject unsupported foreign table column types at DDL time#640sanskar-soni-9 wants to merge 1 commit into
sanskar-soni-9 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Feature
What is the current behavior?
Closes #346
Foreign table column types aren't validated against what
Cellcan actually represent, so an unsupported type fails late and indirectly:Cell's Datum is written into the output slot with no type check, so an incompatible type likepointyields garbage or crashes rather than erroring.rowid_columnOID makesCell::from_polymorphic_datumreturnNone, soDELETE/UPDATEsilently no-op.Either way the user finds out far from the
CREATE FOREIGN TABLEstatement that caused it.What is the new behavior?
A
check_supported_column_typesevent trigger fires onddl_command_endand rejects the offending statement immediately:pg_dependthat it belongs to thewrappersextension, sopostgres_fdw,file_fdwand friends are untouched — verified against a livefile_fdwtable with an unsupported column.CREATE DOMAIN my_text AS textis accepted. All offending columns are reported in a single error rather than one at a time.varchar/bpcharare now genuinely supported.from_polymorphic_datumpreviously matched onlytext, so avarcharrowid_columnsilently failed to parse. This PR adds the missing match arms — a latent bug fix riding along with the validation. Happy to split it into its own PR if you'd rather review it separately.Additional context
On the approach. I weighed an event trigger against
object_access_hook/ProcessUtility_hookand went with the event trigger: it's the documented, version-stable interface for DDL interception, whereas those hooks are internal API with no cross-version guarantee and would require the extension to own global hook chaining. Flagging this explicitly since it's the main design decision in the PR — happy to rework it if you'd prefer a hook-based approach.Known limits.
Cellsupports, not per-FDW. A typeCellhandles but a particular FDW doesn't will still fail at query time; per-FDW type declarations would be a natural follow-up.ALTER TABLEtag as well asALTER FOREIGN TABLE, because Postgres tagsALTER TABLE <foreign_table> ADD COLUMNas the former. It therefore fires on everyALTER TABLEand filters via thepg_dependlookup above — one indexed catalog query on a path that isn't hot.Implementation notes. Registration reuses the build-time versioned-library-name pattern already used for
s3vec, guarded withEXCEPTION WHEN duplicate_objectsoALTER EXTENSION wrappers UPDATEstays idempotent. New#[pg_test]coverage uses a small self-contained test FDW rather than a feature-gated one, so it runs under CI's defaultnative_fdwsinvocation and not just locally. No new dependencies and no changes to the ForeignDataWrapper trait; the only change to existing runtime behavior is the varchar/bpchar fix noted above.