Database
Retrieve as a CSV
Return the response as CSV text instead of parsed JSON.
Switch the response shape to CSV. Lives on the select builder. Sets Accept: text/csv so PostgREST serializes the result set as comma-separated text. data on the returned response is the raw CSV string — feed it to the standard CSV library or write it to disk verbatim.
Signature
builder.csvParameters
This method has no parameters.
Returns
Returns
Supabase::Postgrest::SingleRequestBuilder
A builder that, when .execute'd, returns a SingleAPIResponse whose data is the raw CSV string (PostgREST's text/csv body). The first line is the header row.
Example — export a table to CSV
response = supabase
.from("countries")
.select("id, name, continent")
.order("id")
.csv
.execute
response.data
# => "id,name,continent\n1,Algeria,Africa\n2,Angola,Africa\n..."Example — parse with the standard library
response.data is a plain String, so the standard csv library reads it without any extra plumbing.
require "csv"
csv_text = supabase
.from("countries")
.select("id, name, continent")
.csv
.execute
.data
rows = CSV.parse(csv_text, headers: true)
rows.each { |row| puts "#{row['id']}: #{row['name']}" }Example — write the export straight to a file
File.write(
"countries.csv",
supabase.from("countries").select("*").csv.execute.data
)Sets the text/csv Accept header and returns the raw body — no client-side parsing.