Skip to content
Advertisement

PostgreSQL-10: query JSONB property with multiple types

Assume a table json_table with a column data (jsonb). A sample value would be

I used to run SQL queries like the following:

The problem is that now property d needs to have a dual type, either integer or string. This means that the aforementioned query will crash with

ERROR: invalid input syntax for integer: "d-string-value"

I would like to avoid the obvious solution of creating two properties d_id and d_name.

So, is there any way to query the dual type JSONB property?

Advertisement

Answer

How about casting to text instead?

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement