You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Impossible to use SELECT with JSON_TO_RECORDSET #2191
I would want to select a field from a JSON. It seams right now not possible.
I have a query like this:
WITH to_update as (
SELECT x
FROM JSON_TO_RECORDSET(@auth_users::JSON)
AS x("id"BIGINT, "label"VARCHAR(55))
)
UPDATE auth_users
SET label =to_update.labelFROM to_update
WHEREauth_users.id=to_update.idANDauth_users.user_id= @user_id;
I can simplify to show the error:
SELECT x
FROM JSON_TO_RECORDSET(@users::JSON)
AS x("id"BIGINT, "label"VARCHAR(55));
Here `column "x" does not exist
If I try to use a select all:
SELECT*FROM JSON_TO_RECORDSET(@users::JSON)
AS x("id"BIGINT, "label"VARCHAR(55));
-- orSELECT x.*FROM JSON_TO_RECORDSET(@users::JSON)
AS x("id"BIGINT, "label"VARCHAR(55));
The output ignore it
SELECTFROM JSON_TO_RECORDSET($1::JSON)
AS x("id"BIGINT, "label"VARCHAR(55))
WITH to_update as (
SELECTx.id::BIGINT, x.label::VARCHAR(55)
FROM JSONB_TO_RECORDSET(@auth_users::JSONB)
AS x("id"BIGINT, "label"VARCHAR(55))
)
UPDATE auth_users
SET label =to_update.labelFROM to_update
WHEREauth_users.id=to_update.idANDauth_users.user_id= @user_id;
Activity
realdecisions commentedon Apr 13, 2023
Try to describe in select types for selected columns like select x.id::int8, x.label::varchar in subquery
In my case sqlc with unnest start working only after describing types explicitly for columns in select
intersting.. my subquery not working in playground, but on local machine with shema - all works . ver 1.17.2
Try localy
tcastelly commentedon Apr 14, 2023
Thx, it works for me!
This is my new query