Skip to content

Insert() method never returns inserted data - fundamental bug in data return handling #36

@Vofchuk

Description

@Vofchuk

Bug report

Describe the bug

The Insert() method in the Supabase Go library (postgrest-go) consistently returns empty data ([]uint8 len: 0) regardless of the returning parameter, even when insertion is successful (count > 0). This prevents applications from accessing the inserted data directly from the Insert operation.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Create a Go project with the Supabase Go library
  2. Set up a database table (e.g., "incidents")
  3. Execute an Insert operation with a returning parameter
  4. Check the returned data and count values
  5. Observe that count == 1 (successful insertion) but data is always empty

Code example:

package main

import (
    "fmt"
    "github.com/supabase-community/postgrest-go"
)

func main() {
    client := postgrest.NewClient("your-supabase-url", "your-anon-key", nil)
    
    incident := map[string]interface{}{
        "complain_id": 1,
        "status": "active",
    }
    
    data, count, err := client.
        From("incidents").
        Insert(incident, false, "id", "incident_id,status,location", "exact").
        Execute()
    
    if err != nil {
        panic(err)
    }
    
    fmt.Printf("Count: %d\n", count)  // Output: Count: 1
    fmt.Printf("Data: %v\n", data)    // Output: Data: [] (empty byte slice)
    fmt.Printf("Data length: %d\n", len(data))  // Output: Data length: 0
}

Expected behavior

The data should contain the inserted record(s) when specifying columns in the returning parameter. The method should return the actual inserted data as a byte slice that can be unmarshaled into the appropriate struct.

System information

  • OS: macOS (darwin 24.6.0)
  • Database: Supabase/PostgreSQL
  • RLS: Disabled (confirmed not an RLS issue)

Additional context

Key findings:

  • This is a fundamental library bug affecting ALL Insert operations
  • The issue occurs regardless of the returning parameter (both "*" and specific column names)
  • The insertion itself succeeds, only the data return is broken
  • All existing code in production codebases work around this by ignoring the data return using _

Impact:
This prevents applications from accessing the inserted data directly from the Insert operation, requiring additional queries to retrieve the inserted records, which impacts performance and adds complexity to applications.

Repository evidence:
The issue is reproducible across different tables and returning parameters. In our codebase, all Create* functions work around this by ignoring the data return, indicating this is a known limitation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions