Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/sql/types.sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ from
t.typrelid = 0
or (
select
c.relkind ${props.includeTableTypes ? `in ('c', 'r', 'v', 'm')` : `= 'c'`}
c.relkind ${props.includeTableTypes ? `in ('c', 'r', 'v', 'm', 'p')` : `= 'c'`}
from
pg_class c
where
Expand Down
36 changes: 36 additions & 0 deletions test/db/00-init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,39 @@ ROWS 1
AS $$
SELECT * FROM public.todos WHERE todos."user-id" = user_row.id LIMIT 1;
$$;

-- Function that return the created_ago computed field
CREATE OR REPLACE FUNCTION "public"."created_ago" ("public"."users_audit") RETURNS numeric LANGUAGE "sql"
SET
"search_path" TO '' AS $_$
SELECT ROUND(EXTRACT(EPOCH FROM (NOW() - $1.created_at)));
$_$;

-- Create a partitioned table for testing computed fields on partitioned tables
CREATE TABLE public.events (
id bigint generated by default as identity,
created_at timestamptz default now(),
event_type text,
data jsonb,
primary key (id, created_at)
) partition by range (created_at);

-- Create partitions for the events table
CREATE TABLE public.events_2024 PARTITION OF public.events
FOR VALUES FROM ('2024-01-01') TO ('2025-01-01');

CREATE TABLE public.events_2025 PARTITION OF public.events
FOR VALUES FROM ('2025-01-01') TO ('2026-01-01');

-- Insert some test data
INSERT INTO public.events (created_at, event_type, data)
VALUES
('2024-06-15', 'login', '{"user": "alice"}'),
('2025-03-20', 'logout', '{"user": "bob"}');

-- Function that returns computed field for partitioned table
CREATE OR REPLACE FUNCTION "public"."days_since_event" ("public"."events") RETURNS numeric LANGUAGE "sql"
SET
"search_path" TO '' AS $_$
SELECT ROUND(EXTRACT(EPOCH FROM (NOW() - $1.created_at)) / 86400);
$_$;
Loading