age icon indicating copy to clipboard operation
age copied to clipboard

I have a question about the function of the agtype json operator in version 1.5.0

Open shinhanbyeol opened this issue 2 years ago • 7 comments

i have a question about the phenomenon found in the version of age 1.5.0 The json operator function was fine in 1.4.0 as below query select properties->'ott' from ott_service_1.ott_company; image

However, starting with 1.5.0 and later versions When you create a query, such as version 1.4.0 ERROR: invalid input syntax for type agtype error occurs, however select properties-> 'ott'::text as ott_company_name from netflix_2.ott; I did type casting like this, and the problem was solved.

image

Is this the phenomenon intended in 1.5.0? and Will this continue in future versions?

shinhanbyeol avatar Jan 24 '24 05:01 shinhanbyeol

@shinhanbyeol What version of PG is this on, what version of PG did it previously work on?

jrgemignani avatar Jan 24 '24 18:01 jrgemignani

@jrgemignani 1.5 ,1.4 Both were done in pg 14 version

shinhanbyeol avatar Jan 24 '24 23:01 shinhanbyeol

@shinhanbyeol There appears to be something weird with the definition of -> @Zainab-Saad Could you take a look?

jrgemignani avatar Jan 25 '24 01:01 jrgemignani

psql-16.1-5432-pgsql=# select agtype_object_field(properties, 'name') from xyz._ag_label_vertex;
 agtype_object_field
---------------------
 "John"
(1 row)

psql-16.1-5432-pgsql=# select agtype_object_field_agtype(properties, 'name') from xyz._ag_label_vertex;
ERROR:  invalid input syntax for type agtype
LINE 1: select agtype_object_field_agtype(properties, 'name') from x...
                                                      ^
DETAIL:  Expected agtype value, but found "name".
CONTEXT:  agtype data, line 1: name
psql-16.1-5432-pgsql=#
psql-16.1-5432-pgsql=# select properties->'name' from xyz._ag_label_vertex;
ERROR:  invalid input syntax for type agtype
LINE 1: select properties->'name' from xyz._ag_label_vertex;
                           ^
DETAIL:  Expected agtype value, but found "name".
CONTEXT:  agtype data, line 1: name
psql-16.1-5432-pgsql=#

jrgemignani avatar Jan 25 '24 01:01 jrgemignani

@shinhanbyeol There appears to be something weird with the definition of -> @Zainab-Saad Could you take a look?

Yes, looking into this

Zainab-Saad avatar Jan 25 '24 12:01 Zainab-Saad

@Zainab-Saad Thank you!

jrgemignani avatar Jan 25 '24 16:01 jrgemignani

The error you are getting is because the operator -> is overloaded (in version 1.5.0) with the following possible operands agtype -> agtype agtype -> text agtype -> int

In the query select properties->'ott' from ott_service_1.ott_company;, 'ott' is of the type unknown and when such a type is provided as second argument to the operator ->, postgres chooses the operator agtype -> agtype instead of agtype -> text. And 'ott' is not in valid agtype format (should be '"ott"'), so you get an error.

You can read why specific operator is choosen when unknown type is provided in the operator type resolution section here

Zainab-Saad avatar Jan 26 '24 11:01 Zainab-Saad

This issue is stale because it has been open 45 days with no activity. Remove "Abondoned" label or comment or this will be closed in 7 days.

github-actions[bot] avatar May 11 '24 00:05 github-actions[bot]

This issue was closed because it has been stalled for further 7 days with no activity.

github-actions[bot] avatar May 19 '24 00:05 github-actions[bot]