update_query
Update an existing query in Redash by providing its ID and optionally modifying the SQL, name, data source, schedule, tags, or other properties.
Instructions
Update an existing query in Redash
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| queryId | Yes | ID of the query to update | |
| name | No | New name of the query | |
| data_source_id | No | ID of the data source to use | |
| query | No | SQL query text | |
| description | No | Description of the query | |
| options | No | Query options | |
| schedule | No | Query schedule | |
| tags | No | Tags for the query | |
| is_archived | No | Whether the query is archived | |
| is_draft | No | Whether the query is a draft |
Implementation Reference
- src/index.ts:136-180 (handler)The main handler function for the 'update_query' tool. Extracts queryId and updateData from params, builds an UpdateQueryRequest with only non-undefined fields, then calls redashClient.updateQuery().
async function updateQuery(params: z.infer<typeof updateQuerySchema>) { try { const { queryId, ...updateData } = params; logger.debug(`Update query ${queryId} params: ${JSON.stringify(updateData)}`); // Convert params to UpdateQueryRequest - only include non-undefined fields const queryData: UpdateQueryRequest = {}; // Only add fields that are defined if (updateData.name !== undefined) queryData.name = updateData.name; if (updateData.data_source_id !== undefined) queryData.data_source_id = updateData.data_source_id; if (updateData.query !== undefined) queryData.query = updateData.query; if (updateData.description !== undefined) queryData.description = updateData.description; if (updateData.options !== undefined) queryData.options = updateData.options; if (updateData.schedule !== undefined) queryData.schedule = updateData.schedule; if (updateData.tags !== undefined) queryData.tags = updateData.tags; if (updateData.is_archived !== undefined) queryData.is_archived = updateData.is_archived; if (updateData.is_draft !== undefined) queryData.is_draft = updateData.is_draft; logger.debug(`Calling redashClient.updateQuery with data: ${JSON.stringify(queryData)}`); const result = await redashClient.updateQuery(queryId, queryData); logger.debug(`Update query result: ${JSON.stringify(result)}`); return { content: [ { type: "text", text: JSON.stringify(result, null, 2) } ] }; } catch (error) { logger.error(`Error updating query ${params.queryId}: ${error instanceof Error ? error.message : String(error)}`); return { isError: true, content: [ { type: "text", text: `Error updating query ${params.queryId}: ${error instanceof Error ? error.message : String(error)}` } ] }; } } - src/index.ts:122-134 (schema)Zod schema for the 'update_query' tool input validation. Defines queryId (required, number), and optional fields: name, data_source_id, query, description, options, schedule, tags, is_archived, is_draft.
// Tool: update_query const updateQuerySchema = z.object({ queryId: z.coerce.number(), name: z.string().optional(), data_source_id: z.coerce.number().optional(), query: z.string().optional(), description: z.string().optional(), options: z.any().optional(), schedule: z.any().optional(), tags: z.array(z.string()).optional(), is_archived: z.boolean().optional(), is_draft: z.boolean().optional() }); - src/index.ts:1645-1664 (registration)Registration of the 'update_query' tool in the ListToolsRequestSchema handler, including name, description, and inputSchema definition with all properties and their types/descriptions.
{ name: "update_query", description: "Update an existing query in Redash", inputSchema: { type: "object", properties: { queryId: { type: "number", description: "ID of the query to update" }, name: { type: "string", description: "New name of the query" }, data_source_id: { type: "number", description: "ID of the data source to use" }, query: { type: "string", description: "SQL query text" }, description: { type: "string", description: "Description of the query" }, options: { type: "object", description: "Query options" }, schedule: { type: "object", description: "Query schedule" }, tags: { type: "array", items: { type: "string" }, description: "Tags for the query" }, is_archived: { type: "boolean", description: "Whether the query is archived" }, is_draft: { type: "boolean", description: "Whether the query is a draft" } }, required: ["queryId"] } }, - src/index.ts:2318-2334 (registration)Routing logic in CallToolRequestSchema handler that dispatches 'update_query' tool calls to the updateQuery handler with schema validation.
} else if (name === "update_query") { try { logger.debug(`Validating update_query schema`); const validatedArgs = updateQuerySchema.parse(args); logger.debug(`Schema validation passed for update_query: ${JSON.stringify(validatedArgs)}`); return await updateQuery(validatedArgs); } catch (validationError) { logger.error(`Schema validation failed for update_query: ${validationError}`); return { isError: true, content: [{ type: "text", text: `Invalid parameters for update_query: ${validationError instanceof Error ? validationError.message : String(validationError)}` }] }; } } - src/redashClient.ts:35-45 (schema)The UpdateQueryRequest TypeScript interface defining all optional fields that can be sent to the Redash API when updating a query: name, data_source_id, query, description, options, schedule, tags, is_archived, is_draft.
export interface UpdateQueryRequest { name?: string; data_source_id?: number; query?: string; description?: string; options?: any; schedule?: any; tags?: string[]; is_archived?: boolean; is_draft?: boolean; }