@@ -429,3 +429,39 @@ ROWS 1
429429AS  $$
430430  SELECT  *  FROM  public .todos  WHERE  todos." user-id"   =  user_row .id  LIMIT  1 ;
431431$$;
432+ 
433+ --  Function that return the created_ago computed field
434+ CREATE OR REPLACE  FUNCTION  "public "." created_ago"   (" public"  ." users_audit"  ) RETURNS numeric  LANGUAGE " sql" 
435+ SET 
436+   " search_path"   TO ' '   AS  $_$
437+   SELECT  ROUND(EXTRACT(EPOCH FROM  (NOW() -  $1 .created_at)));
438+ $_$;
439+ 
440+ --  Create a partitioned table for testing computed fields on partitioned tables
441+ CREATE  TABLE  public .events (
442+   id bigint  generated by default as  identity,
443+   created_at timestamptz  default now(),
444+   event_type text ,
445+   data jsonb,
446+   primary key  (id, created_at)
447+ ) partition by range (created_at);
448+ 
449+ --  Create partitions for the events table
450+ CREATE  TABLE  public .events_2024 PARTITION OF public .events 
451+ FOR VALUES  FROM  (' 2024-01-01'  ) TO (' 2025-01-01'  );
452+ 
453+ CREATE  TABLE  public .events_2025 PARTITION OF public .events 
454+ FOR VALUES  FROM  (' 2025-01-01'  ) TO (' 2026-01-01'  );
455+ 
456+ --  Insert some test data
457+ INSERT INTO  public .events  (created_at, event_type, data)
458+ VALUES  
459+   (' 2024-06-15'  , ' login'  , ' {"user": "alice"}'  ),
460+   (' 2025-03-20'  , ' logout'  , ' {"user": "bob"}'  );
461+ 
462+ --  Function that returns computed field for partitioned table
463+ CREATE OR REPLACE  FUNCTION  "public "." days_since_event"   (" public"  ." events"  ) RETURNS numeric  LANGUAGE " sql" 
464+ SET 
465+   " search_path"   TO ' '   AS  $_$
466+   SELECT  ROUND(EXTRACT(EPOCH FROM  (NOW() -  $1 .created_at)) /  86400 );
467+ $_$;
0 commit comments