SQL in the Gemini Era: Bringing Gemini 3.0 to Your Data with AlloyDB AI
Authors: (Linkedin), (Linkedin)
Gemini 3.0 Pro has redefined what is possible with AI, demonstrating PhD-level reasoning and topping the LMArena Leaderboard. With the launch of Gemini 3.0 Flash yesterday, that intelligence is now available at the speed required for production scale! Gemini 3 Flash combines Gemini 3 Pro’s reasoning capabilities with the Flash line’s levels on latency, efficiency, and cost. It not only enables everyday tasks with improved reasoning, but is designed to tackle the most complex agentic workflows.
For developers, the most exciting question isn’t just “What can these models do?” but “How can I use them?”.
Traditionally, integrating a model like Gemini 3.0 meant building complex pipelines to move data out of your database, process it, and move it back. AlloyDB AI eliminates this friction by providing native, in-database AI to operate on your data. In particular, AlloyDB provides powerful, built-in AI functions (for tasks like search, generate, or rank), now powered by Gemini 3, that you can simply use in SQL. The best part? Now you can just vibe in natural language in SQL!
Ready to see the power in action? Below are three use cases demonstrating how you can leverage Gemini 3.0 to instantly enrich your database for unprecedented value and insight. The examples leverage Gemini 3.0 Pro, but can be replaced with Gemini 3.0 Flash.
The Power of AI Functions
When you use AlloyDB’s native AI functions (including ai.generate, ai.rank, and ai.if), you can now leverage the power of Gemini 3.0, our most intelligent model to date.
Gemini 3.0 excels at comprehending the most profound depth and nuance, from grasping the subtle implications of a creative prompt to untangling the layers of a complex query. This deep understanding means the model is much better at discerning the true intent and context of your requests, drastically reducing the need for extensive, iterative prompting.
But what is the real advantage of infusing your AlloyDB enterprise data with Gemini’s ‘world knowledge’, and more importantly, how do you actually implement it?
- The Why: Consider an example of managing raw user feedback: it’s unstructured, noisy, and difficult to parse. Before this data can be used for vector search, it requires significant pre-processing and entity extraction. Rather than maintaining custom logic for knowledge extraction, you can use Gemini’s generation capabilities directly within AlloyDB to transform raw text into structured, searchable insights!
- The How: AlloyDB’s native AI functions simplify this process. Here is how you can use ai.generate to transform that raw feedback into structured data.
SELECT
log_id,
raw_content,
- Use Gemini 3.0 to reason through the raw user feedback and extract structure
ai.generate(
model_id => 'gemini-3-pro-preview',
prompt => 'Analyze this raw customer feedback entry. Extract the the country, service name, and a 1-sentence summary of the feedback. Return as JSON.' || raw_content
) AS structured_feedback
FROM raw_feedback_logs
WHERE user_type <> 'internal';Ready to build? Here are three ways to use AlloyDB’s AI functions, featuring full code samples and reproducible steps for each.
Use Case 1: Unlocking structured insights from unstructured data using ai.generate
Let’s assume your database is full of application logs, error dumps, or raw user feedback. This data is messy, unstructured, and notoriously difficult to query. To make this data ready for vector search, you typically need to clean it and extract key entities first.
Gemini 3.0’s “deep think” capabilities allow it to parse intent and context better than any previous model. Using ai.generate, you can pass raw log strings to the model and ask it to output a structured JSON object containing only the relevant features.
To see this in action, let’s create a table, app_logs, and add some application log data to it.
CREATE TABLE app_logs (
log_id BIGINT,
user_type TEXT,
raw_content TEXT,
structured_analysis TEXT DEFAULT NULL
);
INSERT INTO app_logs (log_id,user_type,raw_content) VALUES
(1001,'external', '2025–12–16 08:00:01 [ERROR] Service: OrderSvc | DbConnectionTimeout: Failed to acquire connection from pool "primary-shard-04" after 5000ms.'),
(1002, 'external', '2025–12–16 08:05:12 [WARN] Service: IdentityProvider | 401 Unauthorized: Bearer token validation failed for user_id=9942. Signature mismatch.'),
(1003, 'external','2025–12–16 08:12:45 [CRITICAL] Service: AnalyticsEngine | OutOfMemoryError: Java heap space. Allocation of 1.2GB array failed. Heap usage 99%.'),
(1004, 'internal','2025–12–16 08:20:00 [ERROR] Service: FileStorage | DiskQuotaExceeded: Write operation failed on volume /mnt/data_02. Available space: 0KB.'),
(1005,'external', '2025–12–16 08:25:33 [ERROR] Service: WebFrontEnd | 404 NotFound: Resource /api/v3/users/profile/settings not found. Upstream returned 404.'),
(1006, 'internal','2025–12–16 08:30:19 [ERROR] Service: InventoryDB | DeadlockDetected: Process 10222 was waiting for lock on transaction_logs; blocked by Process 9881.'),
(1007, 'external','2025–12–16 08:35:50 [WARN] Service: NotificationGateway | GatewayTimeout: External provider "SendGrid" failed to respond within 30s. Retry scheduled.'),
(1008, 'external','2025–12–16 08:42:11 [ERROR] Service: RecommendationEngine | NullPointerException: Attempt to invoke method "getRecommendations()" on null object at StrategyBuilder.java:45.'),
(1009,'internal', '2025–12–16 08:50:05 [WARN] Service: PublicAPI | RateLimitExceeded: Client IP 192.168.1.55 exceeded quota of 1000 req/min. Throttling active.'),
(1010,'external', '2025–12–16 08:55:22 [ERROR] Service: SecureVault | SSLHandshakeException: PKIX path building failed. Certificate chain for "vault.internal" is incomplete.');
SELECT * FROM app_logs;Here are the results of running the SQL snippet above.
Now, let’s use ai.generate to extract structure from the raw operational logs.
SET google_ml_integration.enable_ai_query_engine = TRUE;
CALL google_ml.create_model(
model_id => 'gemini-3-pro-preview',
model_request_url => 'https://aiplatform.googleapis.com/v1/projects/<YOUR_PROJECT_ID>/locations/global/publishers/google/models/gemini-3-pro-preview:generateContent',
model_provider => 'google',
model_type => 'llm',
model_auth_type => 'alloydb_service_agent_iam');
SELECT
log_id,
raw_content,
-- Use Gemini 3.0 to reason through the raw content and extract structure
ai.generate(
model_id => 'gemini-3-pro-preview',
prompt => 'Analyze this raw server log entry. Extract the error code, the service name, and a 1-sentence summary of the root cause. Return as JSON.' || raw_content
) AS structured_analysis
FROM app_logs
WHERE user_type <> 'internal';This result set showcases the best of both worlds: Gemini handles the heavy lifting of parsing unstructured logs, while SQL handles the filtering (i.e. only show data pertaining to ‘external’ users).
Below, the results displayed for easy readability.
By transforming raw text into structured insights before you generate embeddings, you ensure your vector search is based on clean, semantic meaning rather than noise. You can update the value of structured_analysis in the table and then index it for highly accurate similarity searches.
Use Case 2: Financial fraud detection with reasoning using ai.if
In the complex landscape of financial fraud, anomalies are easy to miss. Financial fraud often leverages social engineering, synthetic identities and complex patterns that rule-based systems miss.
Gemini 3.0’s advanced reasoning capabilities can enable you to detect patterns that may be missed with traditional fraud detection models. It excels at peeling apart overlapping layers of a difficult problem. Rather than just generating an assessment, you can use the ai.if function to feed it a sequence of user actions, transaction notes, or chat summaries and ask it to evaluate a binary outcome: Is this fraudulent?
To see this in action, let’s create a transactions table and a transactions_history table.
-- Table for the "Live" transactions being processed
CREATE TABLE IF NOT EXISTS transactions (
transaction_id BIGINT PRIMARY KEY,
user_id BIGINT,
amount NUMERIC(10, 2),
transaction_note TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Table for historical transaction data
CREATE TABLE IF NOT EXISTS transaction_history (
history_id SERIAL PRIMARY KEY,
user_id BIGINT,
merchant_name TEXT,
amount NUMERIC(10, 2),
transaction_date DATE
);Next, let’s add data to the tables. The transaction table has live transaction data, and the history table has historic data on transactions.
-- Insert Live Transactions
INSERT INTO transactions (transaction_id, user_id, amount, transaction_note)
VALUES
(2001, 8801, 54.20, 'POS Purchase: Whole Foods Market'), -- Normal: User shops at grocery stores
(2002, 9942, 4500.00, 'Online Transfer to ABC Holdings Ltd'), -- Fraud?: User usually spends <$50
(2004, 7721, 1.00, 'Service Verification Charge'), -- Fraud?: User has recent auth failures
(2005, 1022, 250.00, 'Delta Airlines Baggage Fee'); -- Normal: User is a frequent traveler
-- Insert Historical Data
INSERT INTO transaction_history (user_id, merchant_name, amount, transaction_date)
VALUES
-- User 8801: The "Grocery & Local" Persona
(8801, 'Whole Foods', 62.10, '2025-12-10'), (8801, 'Shell Gas', 40.00, '2025-12-08'),
(8801, 'Trader Joes', 35.50, '2025-12-05'), (8801, 'Netflix', 15.99, '2025-12-01'),
(8801, 'Whole Foods', 58.00, '2025-11-28'), (8801, 'Starbucks', 6.50, '2025-11-25'),
(8801, 'Safeway', 42.10, '2025-11-20'), (8801, 'Chevron', 38.00, '2025-11-15'),
(8801, 'Whole Foods', 71.20, '2025-11-10'), (8801, 'Local Farmers Market', 25.00, '2025-11-03'),
-- User 9942: The "Small Domestic Micropayer" Persona (High Fraud Risk for $4500)
(9942, 'Starbucks', 5.40, '2025-12-15'), (9942, 'Uber Ride', 12.50, '2025-12-14'),
(9942, 'CVS Pharmacy', 8.99, '2025-12-12'), (9942, 'Target', 45.00, '2025-12-10'),
(9942, 'Spotify', 10.99, '2025-12-05'), (9942, 'App Store', 2.99, '2025-12-01'),
(9942, 'McDonalds', 11.20, '2025-11-28'), (9942, 'Starbucks', 4.50, '2025-11-25'),
(9942, 'Blue Bottle Coffee', 7.00, '2025-11-20'), (9942, 'Uber Pool', 8.50, '2025-11-15'),
-- User 7721: The "Retail Enthusiast" (High Fraud Risk due to recent AUTH_FAIL)
(7721, 'AUTH_FAIL', 0.00, '2025-12-16'), (7721, 'AUTH_FAIL', 0.00, '2025-12-16'),
(7721, 'Walmart', 102.50, '2025-12-01'), (7721, 'Shell Gas', 35.00, '2025-11-25'),
(7721, 'Mcdonalds', 12.00, '2025-11-20'), (7721, 'Home Depot', 89.00, '2025-11-15'),
(7721, 'Amazon.com', 45.20, '2025-11-10'), (7721, 'Target', 15.00, '2025-11-05'),
(7721, 'Walmart', 62.00, '2025-11-01'), (7721, 'Gas Station', 40.00, '2025-10-28'),
-- User 1022: The "Frequent Global Traveler" Persona (Low Fraud Risk for Airlines)
(1022, 'Hilton London', 450.00, '2025-12-10'), (1022, 'Heathrow Express', 30.00, '2025-12-09'),
(1022, 'JFK Parking', 80.00, '2025-11-20'), (1022, 'United Airlines', 300.00, '2025-11-15'),
(1022, 'Uber', 45.00, '2025-11-01'), (1022, 'Delta Airlines', 520.00, '2025-10-25'),
(1022, 'Marriott Tokyo', 600.00, '2025-10-15'), (1022, 'Japan Rail', 120.00, '2025-10-10'),
(1022, 'Duty Free Shop', 85.00, '2025-10-05'), (1022, 'British Airways', 900.00, '2025-09-28');
select * from transactions;
select * from transaction_history;The tables have been created and updated with data:
Now, we leverage ai.if to let Gemini 3.0 act as a security analyst, while also using traditional SQL filtering (i.e. look at recent historic transactions (transaction date > November 1, 2025)).
SET google_ml_integration.enable_ai_query_engine = TRUE;
SELECT
t.transaction_id,
t.user_id,
t.amount,
t.transaction_note,
ai.if(
model_id => 'gemini-3-pro-preview',
prompt => 'Review this transaction note and history. Does the transaction appear to be fraudulent based history of the user?'
|| CONCAT('Note: ', t.transaction_note,
' | History: ',
(SELECT string_agg(merchant_name, ', ')
FROM (SELECT merchant_name
FROM transaction_history h
WHERE h.user_id = t.user_id
AND transaction_date > '2025-11-01'
ORDER BY transaction_date DESC
) as sub)
)
) AS needs_review_flag
FROM transactions t;Here, you are effectively employing an army of AI analysts to review transactions in real-time. By leveraging Gemini 3.0’s reasoning inside the database, you can flag suspicious activity that follows a pattern no hard-coded rule could catch. Transaction entries # 2 and # 3 appear to be fraudulent, as shown below.
Use Case 3: Hyper-personalized retail search using ai.rank
Vector search is an incredible tool for finding semantically similar items. But in retail, “similar” isn’t always “relevant.” A user searching for “running shoes” might get results for hiking boots and athletic socks because of high semantic similarity, while the business wants to prioritize high-margin, in-stock items.
The challenge is: How do you leverage all the valuable context you already have in your database- like the user’s Gold-tier loyalty status, the product’s profit margin, and real-time inventory to rank results with superior accuracy and business logic?
This is where the ai.rank function shines. It allows you to pass a list of good candidates (the initial vector search results) to Gemini 3.0, along with a complex, contextual prompt, and ask the model to re-score the items based on the ultimate relevance for this specific user, right now.
Let’s walk through this with an example. Let’s create a products table that contains details about various bags. Let’s assume the bags in this table are the result of a semantic search query , based on a specific customer search criteria.
CREATE TABLE IF NOT EXISTS products (
product_id INT,
product_name TEXT,
category TEXT,
price NUMERIC(10, 2),
description TEXT
);
INSERT INTO products (product_id, product_name, category, price, description)
VALUES
-- 1. The "Commuter Friendly" Bag
(101, 'The Urban Commuter', 'Bags', 120.00,
'Designed for the modern city dweller. Features a water-resistant waxed canvas body with premium leather trim. Includes a padded, shock-proof laptop sleeve and reinforced stitching. Sleek, minimalist aesthetic suitable for boardrooms.'),
-- 2. Durable but too Casual
(102, 'Campus Hero Pack', 'Bags', 55.00,
'Built for heavy loads. Made from military-grade ballistic nylon with oversized zippers. Features 5 distinct external pockets, mesh water bottle holders, and high-visibility reflective strips for night safety. sporty design.'),
-- 3. Professional but Fragile
(103, 'Executive Brief-Pack', 'Bags', 145.00,
'A slim, structured backpack for the executive. Made from soft, full-grain Italian leather. Ideal for a tablet and a few documents. Note: Leather is sensitive to water and scratches. Not intended for heavy load-bearing.'),
-- 4. Cheap & Basic
(104, 'Standard Daypack', 'Bags', 45.00,
'A simple, lightweight polyester backpack. One main compartment and a small front pocket. Good for gym clothes or light travel. basic functionality.'),
-- 5. Tech-Focused
(105, 'Silicon Valley Tech Loader', 'Bags', 130.00,
'The ultimate bag for engineers. Rigid shell protection for electronics, cable management organizers, and a TSA-friendly laptop compartment. Clean matte black finish that looks sharp in any office environment.');The table has been created, and corresponding data has been added, as shown below.
Now, let’s rank the products in the table based on some additional criteria (see scoring rubric in the query below — higher score for bags that are well suited for technical professionals), using ai.rank:
SET google_ml_integration.enable_ai_query_engine = TRUE;
SELECT *
FROM products
ORDER BY ai.rank(
model_id => 'gemini-3-pro-preview',
prompt => 'Score these bags based on these rules:
(1) Score OF 8 to 10 IF the description says the bag is a good fit for technical professionals.
(2) 4 to 7 IF the description says the bag is a fit for working professionals, who need not be technical.
(3) 1 to 3 IF the description says the bag is a fit for outdoor activities or travel. Here is the product description:
' || description) DESC;The top result is now a bag that is well suited for engineers and technical professionals, as shown below:
The Next Era of Database Intelligence
Gemini 3.0 is Google’s most intelligent model and AlloyDB is Google Cloud’s AI native database, with superior performance and scale. Together they bring the best of PostgreSQL and the best of Google to supercharge your applications.
Whether you are cleaning logs, protecting your users or delivering personalized search results, you can now bring the “Gemini Era” to your database — no complex pipelines required.
Ready to get started? Spin up a free trial AlloyDB instance today and start building with Gemini 3.0. Explore how you can leverage AlloyDB AI’s features to supercharge your application.

