Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2026-10-06 6bac54b555d27f1a85c1e4f011a6e7bd9111b0d0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
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;