From: | Robert Haas <robertmhaas(at)gmail(dot)com> |
---|---|
To: | Joseph Adams <joeyadams3(dot)14159(at)gmail(dot)com> |
Cc: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: JSON manipulation functions |
Date: | 2010-05-27 18:44:38 |
Message-ID: | AANLkTim5eTBvsJPMevAg_mTQ0eHI16kaHYJ2U9I87C13@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Thu, May 27, 2010 at 2:39 PM, Joseph Adams
<joeyadams3(dot)14159(at)gmail(dot)com> wrote:
> I've started implementing the JSON datatype; the repo is at
> http://git.postgresql.org/gitweb?p=json-datatype.git .
>
> On Fri, May 14, 2010 at 1:15 PM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
>> On Thu, May 13, 2010 at 9:47 PM, Joseph Adams
>> <joeyadams3(dot)14159(at)gmail(dot)com> wrote:
>>> Would it be a bad idea to give an enum and a function the same name
>>> (which appears to be allowed by PostgreSQL) ? If so, json_type(json)
>>> could be json_typeof(json) or something instead.
>>
>> No, I think that's a fine idea.
>
> I tried making a function named json_type that has the same name as
> the type json_type. However, this doesn't work as expected:
>
> SELECT json_type('[1,2,3]');
>
> Instead of calling json_type with '[1,2,3]' casted to JSON, it's
> trying to cast '[1,2,3]' to json_type. Is there a way to override
> this behavior, or would I be better off renaming the function?
Well, you should rename either the function or the type, I guess. Not
sure which. Calling it json_typeof would be reasonable...
> Note that if the function were renamed, the literal would implicitly be json:
>
> SELECT json_typeof('[1,2,3]'); -- works
>
> I tried this:
>
> CREATE OR REPLACE FUNCTION json_type(json)
> RETURNS json_type
> AS 'MODULE_PATHNAME','json_get_type'
> LANGUAGE C STRICT IMMUTABLE;
>
> CREATE CAST (json AS json_type) WITH FUNCTION json_type(json);
>
> However, json_type('[1,2,3]') still doesn't work (it doesn't infer
> that '[1,2,3]' should be casted to json first). I also tried each of
> AS ASSIGNMENT and AS IMPLICIT as well.
Yeah, I don't think you want to go that way.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise Postgres Company
From | Date | Subject | |
---|---|---|---|
Next Message | Robert Haas | 2010-05-27 18:49:25 | Re: Idea for getting rid of VACUUM FREEZE on cold pages |
Previous Message | Joseph Adams | 2010-05-27 18:39:37 | Re: JSON manipulation functions |