Select * from 
backend2.transactions as t
left join backend2.transaction_outputs as tout on t.id = tout.transaction_id
--where t.id = 1 and tout.prompt_id = 98
--where t.created_at like '2025-11-12%' and tout.prompt_id = 98
order by transaction_id, prompt_id;


select * from public.transactions
order by "requires_review" desc, "risk_score" desc, "executed_at" desc
limit 12 offset 0;


SELECT * FROM information_schema.columns
WHERE table_schema = 'public' and table_name = 'transactions';

/* Abfrage von Werten in JSONB */
select content_json->'answer' as answer , content_json->
from public.transaction_outputs
where transaction_id = 2 --and prompt_id = 2
order by transaction_id, prompt_id;


-- Einer von mehreren Keys existiert?
SELECT * FROM public.transaction_outputs 
WHERE content_json ?| array['risk_score', 'risk_level', 'risk_details_json'];

select * from backend2.transaction_outputs;


/* Kopieren einer Tabelle von einem Schema in ein neues Schema */
CREATE TABLE public.transaction_outputs AS 
SELECT * FROM backend.transaction_outputs;
/* Prüfen ob alle Daten valides Json sind*/
SELECT content from public.transaction_outputs  
WHERE content IS NOT NULL 
  AND content::jsonb IS NULL;
/* Neue Spalte zur kopierten Tabelle hinzufügen*/
ALTER TABLE public.transaction_outputs
ADD COLUMN content_json jsonb;
/* Kopieren der String Daten in die JSONB Spalte*/
UPDATE public.transaction_outputs 
SET content_json = content::jsonb 
WHERE content IS NOT NULL;
/* Index erstellen*/
CREATE INDEX idx_content_json ON public.transaction_outputs USING gin(content_json);
CREATE INDEX idx_data_gin ON tablename USING gin(data);




