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

Cast key back to text. #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

schinckel
Copy link
Contributor

I needed to make this change to get it to actually allow me to create the function:

[[local]:5432] matt@~ =# CREATE OR REPLACE FUNCTION jsonb_delete_left(a jsonb, b jsonb) 
-# RETURNS jsonb AS 
-# $BODY$
$#     SELECT COALESCE(    
$#         (
$#             SELECT ('{' || string_agg(to_json(key) || ':' || value, ',') || '}')
$#             FROM jsonb_each(a)
$#             WHERE NOT ('{' || to_json(key) || ':' || value || '}')::jsonb <@ b
$#         )
$#     , '{}')::jsonb;
$# $BODY$
-# LANGUAGE sql IMMUTABLE STRICT;
ERROR:  invalid input syntax for type json
LINE 6: ...        SELECT ('{' || string_agg(to_json(key) || ':' || val...
                                                             ^
DETAIL:  Expected JSON value, but found ":".
CONTEXT:  JSON data, line 1: :
Time: 1.076 ms

I needed to make this change to get it to actually allow me to create the function:

<pre>
[[local]:5432] matt@~ =# CREATE OR REPLACE FUNCTION jsonb_delete_left(a jsonb, b jsonb) 
-# RETURNS jsonb AS 
-# $BODY$
$#     SELECT COALESCE(    
$#         (
$#             SELECT ('{' || string_agg(to_json(key) || ':' || value, ',') || '}')
$#             FROM jsonb_each(a)
$#             WHERE NOT ('{' || to_json(key) || ':' || value || '}')::jsonb <@ b
$#         )
$#     , '{}')::jsonb;
$# $BODY$
-# LANGUAGE sql IMMUTABLE STRICT;
ERROR:  invalid input syntax for type json
LINE 6: ...        SELECT ('{' || string_agg(to_json(key) || ':' || val...
                                                             ^
DETAIL:  Expected JSON value, but found ":".
CONTEXT:  JSON data, line 1: :
Time: 1.076 ms
</pre>
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.

2 participants