% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/query.R
\name{cloudos.query}
\alias{cloudos.query}
\title{Execute SQL Query (Orchestrator)}
\usage{
cloudos.query(
  profilename = "",
  cohort_id = "",
  sql = "",
  poll_interval = 2,
  max_wait = 600,
  page_size = 1000,
  all_pages = TRUE
)
}
\arguments{
\item{profilename}{Character. Name of the configured profile to use. If empty or NULL, uses the default profile.}

\item{cohort_id}{Character. ID of the cohort to query.}

\item{sql}{Character. SQL query to execute.}

\item{poll_interval}{Integer. Seconds between status checks (default: 2).}

\item{max_wait}{Integer. Maximum seconds to wait for completion (default: 600).}

\item{page_size}{Integer. Number of rows per page (default: 1000).}

\item{all_pages}{Logical. Fetch all result pages automatically (default: TRUE).
When TRUE, submits multiple async tasks (one per page) to fetch complete results.}
}
\value{
Data frame with query results.
}
\description{
High-level function that orchestrates the full query lifecycle:
submit -> poll status -> fetch results as dataframe.
}
\details{
IMPORTANT: Pagination works by submitting separate tasks for each page. When all_pages=TRUE,
this function submits multiple async tasks (one per page), waits for all to complete,
and combines the results. This may take longer for large result sets.
}
\examples{
\dontrun{
  # Fetch all results
  results <- cloudos.query(
    profilename = "production",
    cohort_id = "699edb4380a6867895f0c9e1",
    sql = "SELECT person_id, gender_concept_id FROM person LIMIT 500"
  )
  
  # Fetch only first page
  results_page1 <- cloudos.query(
    profilename = "production",
    cohort_id = "699edb4380a6867895f0c9e1",
    sql = "SELECT person_id FROM person",
    all_pages = FALSE,
    page_size = 100
  )
}
}
