Skip to content

Functions with Args: never and names matching table columns cause columns to be omitted from select('*') return types #1039

@dabarrell

Description

@dabarrell

Describe the bug

When a postgres function with no arguments has the same name as a column in a table, those columns are omitted from the return type of .select('*') queries.

This seems to be related to ComputedField types in postgrest-js/src/select-query-parser/utils.ts. The ComputedField type checks whether a function's Args extends { '': Row }:

https://github.com/supabase/supabase-js/blob/7ec2df9f02e13fb00cf3d1491f140224f0e35546/packages/core/postgrest-js/src/select-query-parser/utils.ts#L654-L665

When Args is never, this check passes because never extends T is true for all T. The function is then treated as a computed field, and the column is removed from the * result (via Omit<Row, GetComputedFields<...>>)

This was not an issue is supabase cli v1.x, which generated Args: Record<PropertyKey, never> for functions with no args, but broke when it was changed to Args: never in 2.x

Library affected

postgrest-js

Reproduction

No response

Steps to reproduce

In this example, there's a songs table with a column secret, and separately a function secret:

CREATE TABLE songs (
  id uuid PRIMARY KEY,
  name text NOT NULL,
  secret text
);
-- Zero-argument function with same name as column
CREATE FUNCTION secret() RETURNS text AS $$
  SELECT current_setting('request.headers')::json->>'x-secret';
$$ LANGUAGE sql;

Running supabase gen types typescript (CLI v2.x) generates:

// In Tables
songs: {
  Row: {
    id: string
    name: string
    secret: string | null
  }
}
// In Functions
secret: { Args: never; Returns: string }

Then querying:

const { data } = await supabase.from('songs').select('*').single();
// Expected: data.secret is accessible
// Actual: `secret` is missing from the inferred type of `data`

System Info

System:
    OS: macOS 15.5
    CPU: (10) arm64 Apple M1 Max
    Memory: 158.11 MB / 32.00 GB
    Shell: 5.9 - /opt/homebrew/bin/zsh
  Binaries:
    Node: 22.14.0 - /Users/david.barrell/.local/share/mise/installs/node/22.14.0/bin/node
    Yarn: 4.10.3 - /Users/david.barrell/.local/share/mise/installs/node/22.14.0/bin/yarn
    npm: 10.9.2 - /Users/david.barrell/.local/share/mise/installs/node/22.14.0/bin/npm
    bun: 1.2.4 - /Users/david.barrell/.local/share/mise/installs/bun/1.2.4/bin/bun
    Deno: 2.1.4 - /Users/david.barrell/.deno/bin/deno
  Browsers:
    Chrome: 143.0.7499.170
    Firefox: 141.0
    Safari: 18.5
  npmPackages:
    @supabase/ssr: ^0.8.0 => 0.8.0
    @supabase/supabase-js: ^2.93.3 => 2.93.3
    supabase: ^2.74.4 => 2.74.4

Used Package Manager

yarn

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions