pg-redis-fdw / redis_fdw

A PostgreSQL foreign data wrapper for Redis
494 stars 68 forks source link

json and hstore types instead of just text[] is planned? #4

Closed TrurlMcByte closed 10 years ago

TrurlMcByte commented 10 years ago

just text[] is not useful for hashes, currently I do something like

CREATE FOREIGN TABLE redis0_hash1 (key text, value text[])
    SERVER redis_server
   OPTIONS (database '0', tabletype 'hash', tablekeyprefix 'hash:');
select key, hstore(value) as val from redis0_hash1 where defined(hstore(value),'var1');
adunstan commented 10 years ago

You can do similar things with json_object - it was written for just this purpose. See https://bitbucket.org/qooleot/json_object

I doubt we'll ever do hstore, because it's not a builtin type and almost certainly never will be, but we could do a json value I guess. It's not on my priority list, though, meaning either someone else will have to do it, or someone will have to pay me to do it, or you'll probably have to wait a long time.

TrurlMcByte commented 10 years ago

in last 9.3 already exists function hstore_to_json(hstore) in default contribution

adunstan commented 10 years ago

Yes, I know. I wrote it. But calling hstore_to_json(hstore(val)) is horribly inefficient. And it requires you to have the hstore extension installed, which many people do not.

On 11/25/2013 02:57 PM, Trurl McByte wrote:

in last 9.3 already exists function hstore_to_json(hstore) in default contribution

— Reply to this email directly or view it on GitHub https://github.com/pg-redis-fdw/redis_fdw/issues/4#issuecomment-29236134.

TrurlMcByte commented 10 years ago

hstore long time was only one easy/lazy alternative for complicated data (was also xml, but...) And now hstore is supported solution "from the box" and it's very useful for mass/production. in any case json functionality still very limited (no any of "?&", "?|" operators) and my first example looks better as

select key,json_object(value) as val from redis0_hash1 where (json_object(value)->'var1')::text <> ''

but better it's will be like

-- hstore: CREATE FOREIGN TABLE redis0_hash1 (key text, value hstore)...
select key, value->'var1', value->'var2' as val from redis0_hash1 where value ? 'var1';
-- OR json: CREATE FOREIGN TABLE redis0_hash1 (key text, value json)...
select key, value->'var1', value->'var2' as val from redis0_hash1 where value->'var1'' <> '''
adunstan commented 10 years ago

As I mentioned before we will not ever have direct support for hstore values, because that would make the module dependent on the hstore module which it is not now, and I am not going to do that. We could do json. If you want it you can a) do it yourself, b) pay someone else to do it or c) wait until someone else gets around to it.

On 11/25/2013 03:34 PM, Trurl McByte wrote:

hstore long time was only one easy/lazy alternative for complicated data (was also xml, but...) And now hstore is supported solution "from the box" and it's very useful for mass/production. in any case json functionality still very limited (no any of "?&", "?|" operators) and my first example looks better as

select key,json_object(value) as val from redis0_hash1 where (json_object(value)->'var1')::text <> ''

but better it's will be like

-- hstore: CREATE FOREIGN TABLE redis0_hash1 (key text, value hstore)... select key, value->'var1', value->'var2' as val from redis0_hash1 where value ? 'var1'; -- OR json: CREATE FOREIGN TABLE redis0_hash1 (key text, value json)... select key, value->'var1', value->'var2' as val from redis0_hash1 where value->'var1'' <> '''

— Reply to this email directly or view it on GitHub https://github.com/pg-redis-fdw/redis_fdw/issues/4#issuecomment-29239348.

TrurlMcByte commented 10 years ago

mmm.... I'm selecting "a", wrap up it to go. ) Check my question, I'm just want to known if it's planned already.

adunstan commented 10 years ago

What part of "no" don't you understand?

TrurlMcByte commented 10 years ago

This one: "We could do" Relax, I have same problems with my projects, anybody wants something strange, but I'm don't have time to do something usefulness to me.