SET client_min_messages = warning; /* * Oracle SODA vs PostgreSQL SODA differences * ========================================== * * This file is both documentation and a PostgreSQL regression test. Each section * names an Oracle behavior, then executes the corresponding PostgreSQL example. * * A runnable Oracle counterpart is kept in: * src/backend/utils/dbms/dbms_soda/soda_oracle_pg_differences_ora.sql */ CREATE OR REPLACE FUNCTION pg_temp.soda_caught_exception(stmt text) RETURNS bool LANGUAGE plpgsql AS $$ BEGIN EXECUTE stmt; RETURN false; EXCEPTION WHEN OTHERS THEN RETURN true; END; $$; SELECT dbms_soda_drop_collection('DIFF_TX_CREATE') AS cleanup_tx_create; SELECT dbms_soda_drop_collection('DIFF_TX_TRUNCATE') AS cleanup_tx_truncate; SELECT dbms_soda_drop_collection('DIFF_TX_DROP') AS cleanup_tx_drop; SELECT dbms_soda_drop_collection('DIFF_PERSIST_BLOB') AS cleanup_persist_blob; SELECT dbms_soda_drop_collection('DIFF_STORAGE_SHAPE') AS cleanup_storage_shape; /* * Difference 1. CREATE_COLLECTION transaction semantics. * * Oracle: DBMS_SODA.CREATE_COLLECTION is DDL-like; it performs an implicit * commit, so the collection survives ROLLBACK. * * PostgreSQL: collection metadata and the storage table are transactional. * A rollback removes both. */ BEGIN; SELECT pg_catalog.soda_collection_t_get_name( dbms_soda_create_collection( 'DIFF_TX_CREATE', '{"tableName":"soda_diff_tx_create_docs"}' ) )::text AS pg_created_collection; ROLLBACK; SELECT dbms_soda_open_collection('DIFF_TX_CREATE') IS NULL AS pg_create_rolled_back, to_regclass('soda_diff_tx_create_docs') IS NULL AS pg_create_table_rolled_back; /* * Difference 2. TRUNCATE transaction semantics. * * Oracle: SODA TRUNCATE is DDL-like and survives ROLLBACK. * PostgreSQL: soda_collection_truncate uses PostgreSQL TRUNCATE and rolls back * with the surrounding transaction. */ CREATE TEMP TABLE diff_tx_truncate_collection AS SELECT dbms_soda_create_collection( 'DIFF_TX_TRUNCATE', '{"tableName":"soda_diff_tx_truncate_docs"}' ) AS collection; SELECT soda_collection_insert_one( collection, soda_document_t(j_content => '{"tx":"truncate"}'::json) ) AS pg_truncate_seed_status FROM diff_tx_truncate_collection; BEGIN; SELECT soda_collection_truncate(collection) AS pg_truncate_status FROM diff_tx_truncate_collection; ROLLBACK; SELECT soda_operation_count(soda_collection_find(collection)) AS pg_rows_after_truncate_rollback FROM diff_tx_truncate_collection; /* * Difference 3. DROP_COLLECTION transaction semantics. * * Oracle: DROP_COLLECTION is DDL-like and survives ROLLBACK. * PostgreSQL: collection drop rolls back; metadata and storage table remain. */ CREATE TEMP TABLE diff_tx_drop_collection AS SELECT dbms_soda_create_collection( 'DIFF_TX_DROP', '{"tableName":"soda_diff_tx_drop_docs"}' ) AS collection; BEGIN; SELECT dbms_soda_drop_collection('DIFF_TX_DROP') AS pg_drop_status; ROLLBACK; SELECT dbms_soda_open_collection('DIFF_TX_DROP') IS NOT NULL AS pg_drop_rolled_back, to_regclass('soda_diff_tx_drop_docs') IS NOT NULL AS pg_drop_table_rolled_back; /* * Difference 4. BLOB JSON persisted into the default native-JSON collection. * * Oracle: after insert/read from a default native JSON collection, the document * is treated as JSON; GET_BLOB and GET_JSON both work. * * PostgreSQL: content_data_type preserves the original BLOB constructor type. * GET_BLOB works, while GET_JSON raises a content type mismatch. */ CREATE TEMP TABLE diff_blob_collection AS SELECT dbms_soda_create_collection('DIFF_PERSIST_BLOB') AS collection; CREATE TEMP TABLE diff_blob_inserted AS SELECT soda_collection_insert_one_and_get( collection, soda_document_t(b_content => decode('7B2261223A317D', 'hex')::blob) ) AS document FROM diff_blob_collection; CREATE TEMP TABLE diff_blob_found AS SELECT soda_collection_find_one( collection, (SELECT soda_document_get_key(document) FROM diff_blob_inserted) ) AS document FROM diff_blob_collection; SELECT soda_document_get_data_type(document) AS pg_persisted_blob_data_type, encode(soda_document_get_blob(document), 'escape') AS pg_get_blob_value, pg_temp.soda_caught_exception( 'SELECT soda_document_get_json((SELECT document FROM diff_blob_found))' ) AS pg_get_json_throws FROM diff_blob_found; /* * Difference 5. Storage shape. * * Oracle default collections use native JSON storage with hidden RESID/ETAG * columns. PostgreSQL stores documents in a normal table with visible columns, * including content_data_type for method dispatch. */ CREATE TEMP TABLE diff_storage_collection AS SELECT dbms_soda_create_collection( 'DIFF_STORAGE_SHAPE', '{"tableName":"soda_diff_storage_docs"}' ) AS collection; SELECT EXISTS ( SELECT 1 FROM information_schema.columns WHERE table_name = 'soda_diff_storage_docs' AND column_name = 'content_data_type' ) AS pg_has_visible_content_data_type, EXISTS ( SELECT 1 FROM information_schema.columns WHERE table_name = 'soda_diff_storage_docs' AND column_name = 'DATA' AND data_type = 'jsonb' ) AS pg_has_visible_jsonb_data; SELECT dbms_soda_drop_collection('DIFF_TX_TRUNCATE') AS drop_tx_truncate; SELECT dbms_soda_drop_collection('DIFF_TX_DROP') AS drop_tx_drop; SELECT dbms_soda_drop_collection('DIFF_PERSIST_BLOB') AS drop_persist_blob; SELECT dbms_soda_drop_collection('DIFF_STORAGE_SHAPE') AS drop_storage_shape; DROP TABLE IF EXISTS diff_tx_truncate_collection; DROP TABLE IF EXISTS diff_tx_drop_collection; DROP TABLE IF EXISTS diff_blob_collection; DROP TABLE IF EXISTS diff_blob_inserted; DROP TABLE IF EXISTS diff_blob_found; DROP TABLE IF EXISTS diff_storage_collection;