Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Error Codes and Messages

This page provides a comprehensive reference for all error codes and messages that you might encounter while using the pg_ai_query extension.

Function-Specific Errors

generate_query Errors

Error MessageCauseSolution
"API key required. Pass as parameter or configure ~/.pg_ai.config"No API key provided and none configuredAdd API key to config file or pass as parameter
"No API key available for [provider] provider"API key missing for specific providerConfigure API key for the requested provider
"AI API error: [details]"AI service returned an errorCheck API key validity and service status
"Natural language query cannot be empty"Empty input providedProvide a non-empty query description
"Query generation failed: [details]"AI failed to generate queryCheck your description clarity and try again

explain_query Errors

Error MessageCauseSolution
"Query text cannot be empty"Empty query providedProvide a valid SQL query
"Failed to prepare EXPLAIN query: syntax error"Invalid SQL syntaxFix SQL syntax errors
"Failed to execute EXPLAIN query"Query execution failedCheck query validity and permissions
"Failed to connect to SPI"Database connection issueCheck database connectivity
"No output from EXPLAIN query"EXPLAIN returned no resultsVerify query syntax and structure

get_database_tables Errors

Error MessageCauseSolution
"Failed to connect to SPI"Database connection issueCheck database connectivity
"Failed to execute query"Database query failedCheck permissions and database status
"No tables found"No user tables in databaseCreate tables or check schema permissions

get_table_details Errors

Error MessageCauseSolution
"Table '[table_name]' does not exist"Specified table not foundCheck table name and schema
"Failed to get table details: [details]"Error retrieving table infoCheck permissions and table existence

Debugging Commands

-- Check extension status
SELECT extname, extversion FROM pg_extension WHERE extname = 'pg_ai_query';

-- Test basic functionality
SELECT generate_query('SELECT 1');

-- Check function permissions
\df generate_query

See Also