JavaScript: select

Perform a SELECT query on the table or view.

Parameters

Examples

Getting your data

const { data, error } = await supabase
  .from('characters')
  .select()

Handling errors

const { data, error } = await supabase.from('characters').select()
if (error) {
  // Logs the full error: message, code, details, and hint.
  console.error(error)
  return
}

Selecting specific columns

const { data, error } = await supabase
  .from('characters')
  .select('name')

Query referenced tables

const { data, error } = await supabase
  .from('orchestral_sections')
  .select(`
    name,
    instruments (
      name
    )
  `)

Query referenced tables with spaces in their names

const { data, error } = await supabase
  .from('orchestral sections')
  .select(`
    name,
    "musical instruments" (
      name
    )
  `)

Query referenced tables through a join table

const { data, error } = await supabase
  .from('users')
  .select(`
    name,
    teams (
      name
    )
  `)
  

Query the same referenced table multiple times

const { data, error } = await supabase
  .from('messages')
  .select(`
    content,
    from:sender_id(name),
    to:receiver_id(name)
  `)

// To infer types, use the name of the table (in this case `users`) and
// the name of the foreign key constraint.
const { data, error } = await supabase
  .from('messages')
  .select(`
    content,
    from:users!messages_sender_id_fkey(name),
    to:users!messages_receiver_id_fkey(name)
  `)

Filtering through referenced tables

const { data, error } = await supabase
  .from('instruments')
  .select('name, orchestral_sections(*)')
  .eq('orchestral_sections.name', 'percussion')

Querying referenced table with count

const { data, error } = await supabase
  .from('orchestral_sections')
  .select(`*, instruments(count)`)

Querying with count option

const { count, error } = await supabase
  .from('characters')
  .select('*', { count: 'exact', head: true })

Querying JSON data

const { data, error } = await supabase
  .from('users')
  .select(`
    id, name,
    address->city
  `)

Querying referenced table with inner join

const { data, error } = await supabase
  .from('instruments')
  .select('name, orchestral_sections!inner(name)')
  .eq('orchestral_sections.name', 'woodwinds')
  .limit(1)

Switching schemas per query

const { data, error } = await supabase
  .schema('myschema')
  .from('mytable')
  .select()