\set QUIET 1 \pset pager off \pset tuples_only on \pset format unaligned \pset footer off SET client_min_messages = warning; CREATE OR REPLACE FUNCTION pg_temp.demo_soda_document_cursor_methods() RETURNS SETOF text LANGUAGE plpgsql AS $$ DECLARE v_collection soda_collection_t; v_doc soda_document_t; v_cursor soda_cursor_t; v_closed_error bool := false; BEGIN PERFORM dbms_soda_drop_collection('DEMO_SODA_TYPES'); EXECUTE 'DROP TABLE IF EXISTS demo_soda_types_docs'; RETURN NEXT ''; RETURN NEXT '1. SODA_DOCUMENT_T'; RETURN NEXT format('GET_BLOB -> %s', encode(soda_document_t_get_blob( soda_document_t(b_content => decode('7B226B696E64223A22626C6F62227D', 'hex')::blob) ), 'escape')); RETURN NEXT format('GET_CLOB -> %s', soda_document_t_get_clob(soda_document_t(c_content => '{"kind":"clob document"}'::clob))); v_collection := dbms_soda_create_collection( 'DEMO_SODA_TYPES', '{"tableName":"demo_soda_types_docs","creationTimeColumn":{"name":"CREATED_ON"},"lastModifiedColumn":{"name":"LAST_MODIFIED"}}' ); v_doc := soda_collection_t_insert_one_and_get( v_collection, soda_document_t(j_content => '{"title":"First document","n":1}'::json) ); RETURN NEXT format('GET_CREATED_ON -> %s', soda_document_t_get_created_on(v_doc)); RETURN NEXT format('GET_DATA_TYPE -> varchar2=%s, blob=%s, clob=%s, json=%s', soda_document_t_get_data_type(soda_document_t(v_content => '{"v":1}'::varchar2)), soda_document_t_get_data_type(soda_document_t(b_content => decode('7B7D', 'hex')::blob)), soda_document_t_get_data_type(soda_document_t(c_content => '{"c":1}'::clob)), soda_document_t_get_data_type(soda_document_t(j_content => '{"j":1}'::json))); RETURN NEXT format('GET_LAST_MODIFIED -> %s', soda_document_t_get_last_modified(v_doc)); RETURN NEXT format('GET_MEDIA_TYPE -> default=%s, custom=%s', soda_document_t_get_media_type(soda_document_t(v_content => '{"default":true}'::varchar2)), soda_document_t_get_media_type(soda_document_t(v_content => 'plain text'::varchar2, media_type => 'text/plain'::varchar2))); RETURN NEXT format('GET_VARCHAR2 -> %s', soda_document_t_get_varchar2(soda_document_t(v_content => '{"kind":"varchar2 document"}'::varchar2))); RETURN NEXT format('GET_VERSION -> %s', soda_document_t_get_version(v_doc)); RETURN NEXT format('CONSTRUCTOR -> handle_created=%s', soda_document_t(key => 'constructor_key'::varchar2, j_content => '{"created_by":"constructor"}'::json) IS NOT NULL); RETURN NEXT format('GET_KEY -> %s', soda_document_t_get_key(soda_document_t(key => 'demo_key_123'::varchar2, v_content => '{"kind":"key demo"}'::varchar2))); RETURN NEXT format('GET_JSON -> kind=%s', soda_document_t_get_json(soda_document_t(j_content => '{"kind":"json document","ok":true}'::json)) ->> 'kind'); RETURN NEXT ''; RETURN NEXT '2. SODA_CURSOR_T'; PERFORM soda_collection_t_insert_one( v_collection, soda_document_t(j_content => '{"title":"Second document","n":2}'::json) ); v_cursor := soda_operation_t_get_cursor(soda_collection_t_find(v_collection)); RETURN NEXT format('HAS_NEXT before NEXT -> %s', soda_cursor_t_has_next(v_cursor)); v_doc := soda_cursor_t_next(v_cursor); RETURN NEXT format('NEXT document #1 title -> %s', soda_document_t_get_json(v_doc) ->> 'title'); RETURN NEXT format('HAS_NEXT after NEXT -> %s', soda_cursor_t_has_next(v_cursor)); v_doc := soda_cursor_t_next(v_cursor); RETURN NEXT format('NEXT document #2 title -> %s', soda_document_t_get_json(v_doc) ->> 'title'); RETURN NEXT format('HAS_NEXT at end -> %s', soda_cursor_t_has_next(v_cursor)); RETURN NEXT format('CLOSE -> %s', soda_cursor_t_close(v_cursor)); BEGIN PERFORM soda_cursor_t_next(v_cursor); EXCEPTION WHEN OTHERS THEN v_closed_error := true; END; RETURN NEXT format('NEXT after CLOSE throws -> %s', v_closed_error); RETURN NEXT ''; RETURN NEXT '3. SODA_OPERATION_T / SODA_COLLECTION_T'; PERFORM soda_collection_t_drop_index(v_collection, 'DEMO_SODA_TYPES_TITLE_IDX', true); RETURN NEXT format('HINT count -> %s', soda_operation_t_count( soda_operation_t_hint(soda_collection_t_find(v_collection), 'MONITOR') )); RETURN NEXT format('SAMPLE count in 0..2 -> %s', soda_operation_t_count( soda_operation_t_sample(soda_collection_t_find(v_collection), 50.0, 42) ) BETWEEN 0 AND 2); RETURN NEXT format('CREATE_INDEX status -> %s', soda_collection_t_create_index( v_collection, '{"name":"DEMO_SODA_TYPES_TITLE_IDX","fields":[{"path":"$.title","datatype":"string","order":"asc"}]}' )); RETURN NEXT format('GET_INDEX visible -> %s', soda_collection_t_get_index(v_collection, 'DEMO_SODA_TYPES_TITLE_IDX') LIKE '%DEMO_SODA_TYPES_TITLE_IDX%'); PERFORM dbms_soda_drop_collection('DEMO_SODA_TYPES'); EXECUTE 'DROP TABLE IF EXISTS demo_soda_types_docs'; END; $$; SELECT * FROM pg_temp.demo_soda_document_cursor_methods();