0

I have two tables in postgresql.

  1. the first (product) has sku json row ([149461190])
  2. the second (item) has an ordinary sku column

How can I join them on sku? I tried this, but it didn't work. cannot recognize input near 'jsonb_to_recordset' '(' 'ps' in joinSourcePart

  select * from product ps
, jsonb_to_recordset(ps.sku -> 'ps_sku') as (sku text)
join item v using sku
       
5
  • Please append your JSON structure and fields, Also which column on item table do you want to join? Commented Nov 2, 2021 at 7:02
  • json column from the first table looks like this column name sku [149408204], [149461190], [149422714] Commented Nov 2, 2021 at 7:09
  • the second table also has sku column, it contains sky's but not in a json: 149461190, 149422714 Commented Nov 2, 2021 at 7:11
  • I want to join product.sku which is a json, on item.sku Commented Nov 2, 2021 at 7:11
  • 1
    You should change the data model and not use JSON or arrays for that purpose. Commented Nov 2, 2021 at 7:35

1 Answer 1

1

I hope this query help you, You can see data structure and sample data in dbfiddle

select 
  *
from  
  product p
  cross join jsonb_array_elements_text(p.sku -> 'ps_sku') as j(sku)
  inner join item i on i.sku = j.sku :: numeric
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, but again a mistake ->> org.apache.hadoop.hive.ql.parse.ParseException:line 5:39 cannot recognize input near 'jsonb_array_elements_text' '(' 'p' in joinSourcePart

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.