Skip to content

Commit dcca897

Browse files
yahondajoschugclaude
committed
Remap TIMESTAMP(n) WITH LOCAL TIME ZONE to standard form
Oracle 18c and later reports the data type as "TIMESTAMP(6) WITH LOCAL TIME ZONE" in ALL_TAB_COLS, whereas older versions used "TIMESTAMP WITH LOCAL TIME ZONE". Normalize to the standard form to avoid type conversion errors. Based on rsim#208 Co-Authored-By: Jochen Schug <4573581+joschug@users.noreply.github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 39cf870 commit dcca897

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

lib/plsql/procedure.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,10 @@ def get_field_definitions(argument_metadata) # :nodoc:
397397

398398
col_no, col_name, col_type_name, col_length, col_precision, col_scale, col_char_length, col_char_used = r
399399

400+
if col_type_name =~ /\ATIMESTAMP\(\d+\) WITH LOCAL TIME ZONE\z/
401+
col_type_name = "TIMESTAMP WITH LOCAL TIME ZONE"
402+
end
403+
400404
fields[col_name.downcase.to_sym] = {
401405
position: col_no.to_i,
402406
data_type: col_type_name,

spec/plsql/procedure_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2385,3 +2385,37 @@ def new_candidate(status)
23852385
expect { plsql.test_func(p_STRING: "xxx") }.not_to raise_error
23862386
end
23872387
end
2388+
2389+
describe "Function with table type containing TIMESTAMP WITH LOCAL TIME ZONE" do
2390+
before(:all) do
2391+
plsql.connect! CONNECTION_PARAMS
2392+
plsql.execute "CREATE TABLE test_timestamp_ltz (id NUMBER, ts TIMESTAMP WITH LOCAL TIME ZONE)"
2393+
plsql.execute <<-SQL
2394+
CREATE OR REPLACE PACKAGE test_timestamp_ltz_pkg IS
2395+
TYPE t_tab IS TABLE OF test_timestamp_ltz%ROWTYPE;
2396+
FUNCTION test_fn RETURN t_tab PIPELINED;
2397+
END;
2398+
SQL
2399+
plsql.execute <<-SQL
2400+
CREATE OR REPLACE PACKAGE BODY test_timestamp_ltz_pkg IS
2401+
FUNCTION test_fn RETURN t_tab PIPELINED IS
2402+
BEGIN
2403+
NULL;
2404+
END;
2405+
END;
2406+
SQL
2407+
end
2408+
2409+
after(:all) do
2410+
plsql.execute "DROP PACKAGE test_timestamp_ltz_pkg" rescue nil
2411+
plsql.execute "DROP TABLE test_timestamp_ltz" rescue nil
2412+
plsql.logoff
2413+
end
2414+
2415+
it "should remap TIMESTAMP(n) WITH LOCAL TIME ZONE to TIMESTAMP WITH LOCAL TIME ZONE" do
2416+
metadata = plsql.test_timestamp_ltz_pkg.test_fn.arguments
2417+
return_metadata = PLSQL::Procedure.find(plsql, :test_fn, "TEST_TIMESTAMP_LTZ_PKG")
2418+
fields = return_metadata.return[0][:element][:fields]
2419+
expect(fields[:ts][:data_type]).to eq("TIMESTAMP WITH LOCAL TIME ZONE")
2420+
end
2421+
end

0 commit comments

Comments
 (0)