isra36

Text to working SQL query

For developers who know logic but forget SQL query syntax. How it differs from GPT: It double-checks and gives working SQL query and details of the process.

Let's say you have a task:

Check whether {pattern}_id foreign key columns have indexes across all tables in your PostgreSQL database.

You give the prompt, and the isra36 agent gets to work:

1

It generates PostgreSQL test environment (sandbox) tailored to your specific task

SQL Query
CREATE TABLE users ( id SERIAL PRIMARY KEY, username TEXT NOT NULL );
    CREATE TABLE posts ( id SERIAL PRIMARY KEY, "user_id" INT REFERENCES users(id) NOT NULL,
           content TEXT NOT NULL );
    CREATE TABLE comments ( id SERIAL PRIMARY KEY, "post_id" INT REFERENCES posts(id),
          "user_id" INT REFERENCES users(id), message TEXT );
    
    INSERT INTO users (username) VALUES ('alice'), ('bob'), ('carol');
    INSERT INTO posts ("user_id", content) VALUES (1, 'Post by Alice'), (2, 'Post by Bob');
    INSERT INTO comments ("post_id", "user_id", message) VALUES 
    (1, 2, 'Bob comments on Alice''s post'), (2, 1, 'Alice comments on Bob''s post');
    
    
    -- Add index on comments "post_id" 
    CREATE INDEX "idx_comments_post_id" ON comments("post_id");
                    
2

You get a visualization of the sandbox

Code Execution in Sandbox
3

It generates an SQL query to solve your task

Generated Query
SELECT c.relname                                                   AS table_name,
           a.attname                                                   AS foreign_key_column,
           CASE WHEN i.indexrelid IS NOT NULL THEN 'YES' ELSE 'NO' END AS has_index
    FROM pg_constraint fk
             JOIN pg_class c ON fk.conrelid = c.oid
             JOIN pg_attribute a ON a.attrelid = c.oid AND a.attnum = ANY (fk.conkey)
             LEFT JOIN LATERAL ( SELECT i.indexrelid
                                 FROM pg_index i
                                 WHERE i.indrelid = c.oid 
                                 AND (a.attnum = ANY (i.indkey)) ) i ON true
    WHERE fk.contype = 'f'
      AND a.attname ~ '_id$'
    ORDER BY table_name, foreign_key_column;
4

It runs the generated code in the sandbox.

While executing the SQL query, it may encounter errors. In that case, you can either switch to Auto Error Fixing Mode or provide manual instructions. Auto Error Fixing Mode includes a safety limit to prevent infinite loops

Code Execution in Sandbox
5

You get the result of the SQL execution.

This result confirms that the SQL query works as intended, saving you the need to double-check it. Just compare the data from the sandbox with the output. As shown, the agent uses diverse test data—both positive and negative cases—to validate the query.

Query Results ✓ Success
table_name foreign_key_column has_index
posts user_id NO
comments post_id YES
comments user_id NO

The core of our platform, Ai agent built on N8N, is now open source

View on GitHub

Contact us: contact@isra36.com

Platform Screenshot