Lars
05/14/2022, 12:59 PMsql
CREATE OR REPLACE FUNCTION public.updateoffset(site text, offsetnumber integer, toscrape integer)
RETURNS void
LANGUAGE sql
AS $function$
update settings set "offset" = coalesce("offset", '{}') || '{"$2": {"toscrape":$3}}'
where site = $1;
$function$
calling it via: sql
SELECT * FROM public.updateoffset('test', 2, 2)
burggraf
05/14/2022, 2:01 PMcoalesce("offset", '{}')
what is "offset" here? I don't see any variable called offset anywhere in the function.Lars
05/14/2022, 2:10 PMLars
05/14/2022, 2:12 PMLars
05/14/2022, 2:14 PM{
"100": {
"toscrape": 103
}
}
burggraf
05/14/2022, 2:18 PM'{"$2": {"toscrape":$3}}'
to
'{"$2": {"toscrape":$3}}'::JSONB
burggraf
05/14/2022, 2:19 PMLars
05/14/2022, 2:20 PMLars
05/14/2022, 2:22 PMERROR: invalid input syntax for type json
LINE 7: ...ttings set "offset" = coalesce("offset", '{}') || '{"$2": {"...
^
DETAIL: Token "$" is invalid.
CONTEXT: JSON data, line 1: {"$2": {"toscrape":$... 0.000 seconds. (Line 1).
Lars
05/14/2022, 2:23 PMLars
05/14/2022, 2:24 PMLars
05/14/2022, 2:24 PMburggraf
05/14/2022, 2:26 PMburggraf
05/14/2022, 2:26 PMLars
05/14/2022, 2:27 PMsql
update settings
set "offset" =
coalesce("offset", '{}') || format('{"%s": {"toscrape":%s}}', $2, $3)::jsonb
where site = $1;
Lars
05/14/2022, 2:27 PMburggraf
05/14/2022, 2:28 PM