diff --git a/google-cloud-spanner/acceptance/spanner/client/params/pgoid_test.rb b/google-cloud-spanner/acceptance/spanner/client/params/pgoid_test.rb new file mode 100644 index 00000000..0fdaf03f --- /dev/null +++ b/google-cloud-spanner/acceptance/spanner/client/params/pgoid_test.rb @@ -0,0 +1,28 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require "spanner_helper" + +describe "Spanner Client", :params, :bool, :spanner do + let(:db) { spanner_pg_client } + + it "queries and returns a PG.OID parameter" do + skip if emulator_enabled? + results = db.execute_query "SELECT $1 AS value", params: { p1: 123 }, types: { p1: :PG_OID } + + _(results).must_be_kind_of Google::Cloud::Spanner::Results + _(results.fields[:value]).must_equal :INT64 + _(results.rows.first[:value]).must_equal 123 + end +end diff --git a/google-cloud-spanner/acceptance/spanner/client/types/pgoid_test.rb b/google-cloud-spanner/acceptance/spanner/client/types/pgoid_test.rb new file mode 100644 index 00000000..fad47580 --- /dev/null +++ b/google-cloud-spanner/acceptance/spanner/client/types/pgoid_test.rb @@ -0,0 +1,29 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require "spanner_helper" + +describe "Spanner Client", :types, :oid, :spanner do + let(:db) { spanner_pg_client } + let(:table_name) { "stuffs" } + + it "queries pg.oid" do + skip if emulator_enabled? + results = db.execute_sql "select 123::oid as value" + + _(results).must_be_kind_of Google::Cloud::Spanner::Results + _(results.fields.to_h).must_equal({ value: :INT64 }) + _(results.rows.first.to_h).must_equal({ value: 123 }) + end +end diff --git a/google-cloud-spanner/lib/google/cloud/spanner/convert.rb b/google-cloud-spanner/lib/google/cloud/spanner/convert.rb index 2f86eb69..65d39789 100644 --- a/google-cloud-spanner/lib/google/cloud/spanner/convert.rb +++ b/google-cloud-spanner/lib/google/cloud/spanner/convert.rb @@ -183,7 +183,9 @@ def grpc_type_for_field field when :PG_NUMERIC V1::Type.new(code: :NUMERIC, type_annotation: :PG_NUMERIC) when :PG_JSONB - V1::Type.new(code: :JSON, type_annotation: :PG_JSONB) + V1::Type.new(code: :JSON, type_annotation: :PG_JSONB) + when :PG_OID + V1::Type.new(code: :INT64, type_annotation: :PG_OID) else V1::Type.new(code: field) end