Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved support of hstore for case when hstore extension is created inside a PG schema #83

Closed
wants to merge 1 commit into from

Conversation

romul
Copy link
Contributor

@romul romul commented Jun 28, 2015

Assume we have hstore extension created in such the way:
CREATE EXTENSION IF NOT EXISTS hstore WITH SCHEMA test;
So we will get the following type info:

%Postgrex.TypeInfo{
  array_elem: 0, 
  base_type: 0, 
  comp_elems: [], 
  input: "test.hstore_in", 
  oid: 21066, 
  output: "test.hstore_out", 
  receive: "test.hstore_recv", 
  send: "test.hstore_send", 
  type: "hstore"
}

B/c of schema name is not a constant, only type field could be matched for sure.

…inside a PG schema,

for example
CREATE EXTENSION IF NOT EXISTS hstore WITH SCHEMA test;
@ericmj
Copy link
Member

ericmj commented Jun 28, 2015

See my reply on the mailing list [1]. Please send a PR that parses out the schema name from the function name.

[1] https://groups.google.com/d/msg/elixir-ecto/1UmWWZ0_xZE/j5t_Jt9gPNYJ

@ericmj ericmj closed this Jun 28, 2015
@romul
Copy link
Contributor Author

romul commented Jun 28, 2015

Do you mean removing schema prefix for TypeInfo fields in Types.build_types/1?

@ericmj
Copy link
Member

ericmj commented Jun 28, 2015

Yes

@romul
Copy link
Contributor Author

romul commented Jun 28, 2015

Unfortunately it isn't enough.
Types are preloaded with Types.bootstrap_query/2, which also use send matchers in SQL query like

SELECT t.oid, t.typname, t.typsend, t.typreceive, t.typoutput, t.typinput,
       t.typelem, coalesce(r.rngsubtype, 0), ARRAY (
  SELECT a.atttypid
  FROM pg_attribute AS a
  WHERE a.attrelid = t.typrelid AND a.attnum > 0 AND NOT a.attisdropped
  ORDER BY a.attnum
)
FROM pg_type AS t
LEFT JOIN pg_range AS r ON r.rngtypid = t.oid
WHERE
  t.typname::text = ANY ((ARRAY[])::text[]) OR
  t.typsend::text = ANY ((ARRAY['array_send', 'range_send', 'record_send', 'cidsend', 'xidsend', 'regtypesend', 'regclasssend', 'regoperatorsend', 'regopersend', 'regproceduresend', 'regprocsend', 'oidsend', 'hstore_send', 'unknownsend', 'tidsend', 'enum_send', 'interval_send', 'timestamptz_send', 'timestamp_send', 'timetz_send', 'time_send', 'date_send', 'uuid_send', 'numeric_send', 'float8send', 'float4send', 'int8send', 'int4send', 'int2send', 'byteasend', 'varcharsend', 'citextsend', 'textsend', 'bpcharsend', 'boolsend', 'void_send'])::text[]) OR
  t.typreceive::text = ANY ((ARRAY[])::text[]) OR
  t.typoutput::text = ANY ((ARRAY[])::text[]) OR
  t.typinput::text = ANY ((ARRAY[])::text[])

I think, we should admit, that hstore could not be matched by typsend, else we will end up with ugly workarounds like removing schema from t.typsend::text directly in SQL.
Here is a complete fix for hstore: romul@52f095d, which eliminates need in writing own Postgrex extension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants