CREATE FUNCTION schema(
  p_table_name text,
  p_schema_name text DEFAULT 'public'
) RETURNS jsonb AS $$ BEGIN RETURN (
  SELECT jsonb_object_agg(
      column_name,
      jsonb_build_object(
        'is_nullable',
        (is_nullable = 'YES'),
        'type',
        udt_name
      )
    )
  FROM information_schema.columns
  WHERE table_schema = p_schema_name
    AND table_name = p_table_name
);
END;
$$ LANGUAGE plpgsql;
-- example usage (defaults to public schema):
-- SELECT schema('users');
-- SELECT schema('users', 'public');