From: Valentine Gogichashvili <valgog@gmail.com>
To: pgsql-jdbc@postgresql.org
Subject: Type OID search does not support search_path and multiple schemas
Date: Tue, 8 Mar 2011 18:18:37 +0100
Message-ID: <20110308183723.08A5B1337B93@mail.postgresql.org> (raw)
[Reposting it now via mail-list directly and not via Google Groups]
When searching for OID of a Type, current search_path is not considered and
if type with the same name exists in several schemas, not a valid OID is
fetched to be cached in TypeInfoCache class.
One of the possible solutions, would be to use select
'schema_name.type_name'::regtype::oid to get the OID. But as the lookup is
now done without using schema name this method is not easy to be used with
the current implementation of the TypeInfoCache...
My patch of the file org/postgresql/jdbc2/TypeInfoCache.java, that would
work for search_path's that contain schema names without " and , charachters
(and version lookup is not really done quite nicely as I am connecting now
only to 9.0 version of the DB... Anyway it is better, than a current
implementation:
190,203c190,192
< String sql;
<
< if (_conn.haveMinimumServerVersion("8.4")) {
< sql = "select distinct on ( typname )
typinput='array_in'::regproc, typtype\n" +
< " from pg_type as t \n" +
< " join pg_namespace as n on typnamespace = n.oid
\n" +
< " left join ( select row_number() over() as rank,
\n" +
< " case when n = '\"$user\"' then
current_user else btrim(n,' \"') end as schema_name \n" +
< " from
regexp_split_to_table(current_setting('search_path'), E', ?' ) as r(n) ) as
r on nspname = schema_name \n" +
< " where typname = ? \n" +
< " order by typname, rank nulls last, oid desc";
< } else {
< // actually this is not correct, but we do not care for
that old versions now
< sql = "SELECT typinput='array_in'::regproc, typtype FROM
pg_type WHERE typname = ? order by oid desc";
---
> String sql = "SELECT typinput='array_in'::regproc, typtype
FROM ";
> if (_conn.haveMinimumServerVersion("7.3")) {
> sql += "pg_catalog.";
204a194
> sql += "pg_type WHERE typname = ?";
248,256c238,239
< if (_conn.haveMinimumServerVersion("8.4")) {
< sql = "select distinct on ( typname ) t.oid\n" +
< " from pg_type as t \n" +
< " join pg_namespace as n on typnamespace = n.oid
\n" +
< " left join ( select row_number() over() as rank,
\n" +
< " case when n = '\"$user\"' then
current_user else btrim(n, ' \"') end as schema_name \n" +
< " from
regexp_split_to_table(current_setting('search_path'), E', ?' ) as r(n) ) as
r on nspname = schema_name \n" +
< " where typname = ? \n" +
< " order by typname, rank nulls last, oid desc";
---
> if (_conn.haveMinimumServerVersion("7.3")) {
> sql = "SELECT oid FROM pg_catalog.pg_type WHERE typname =
?";
Please consider the environment before printing this email.
E-mail messages may contain viruses, worms, or other malicious code. By reading the message and opening any attachments, the recipient accepts full responsibility for taking protective action against such code. Henry Schein is not liable for any loss or damage arising from this message.
The information in this email is confidential and may be legally privileged. It is intended solely for the addressee(s). Access to this e-mail by anyone else is unauthorized.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: valgog@gmail.com
Subject: Re: Type OID search does not support search_path and multiple schemas
In-Reply-To: <20110308183723.08A5B1337B93@mail.postgresql.org>
References: <20110308183723.08A5B1337B93@mail.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox