A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cloud.google.com/sql/docs/postgres/write-sql-gemini below:

Write SQL with Gemini assistance | Cloud SQL for PostgreSQL

Skip to main content Write SQL with Gemini assistance

Stay organized with collections Save and categorize content based on your preferences.

Preview — Gemini Code Assist

This feature is subject to the "Pre-GA Offerings Terms" in the General Service Terms section of the Service Specific Terms. You can process personal data for this feature as outlined in the Cloud Data Processing Addendum, subject to the obligations and restrictions described in the agreement under which you access Google Cloud. Pre-GA features are available "as is" and might have limited support. For more information, see the launch stage descriptions.

This document describes how you can use Gemini, an AI-powered collaborator in Google Cloud, to help you do the following in Cloud SQL Studio:

Learn how and when Gemini for Google Cloud uses your data.

This document is intended for database administrators and data engineers who are familiar with SQL, data analysis, and Cloud SQL. If you're new to Cloud SQL, see Cloud SQL overview.

Note: Coding assistance is part of Gemini Code Assist and is available at no charge until it's included in Gemini Code Assist Standard edition. This change will be communicated at a later date. At that time, you will need to acquire a Gemini Code Assist Standard edition license to continue to use coding assistance in Cloud SQL Studio. Before you begin
  1. To complete the tasks in this document, ensure that you have the necessary Identity and Access Management (IAM) permissions.
  2. Confirm access to Cloud SQL Studio. If you don't have access to Cloud SQL Studio, then see Cloud SQL Studio required roles and permissions
  3. Optional: To follow along with the examples in this document, create a Singers table using the following schema:

    CREATE TABLE
    Singers (
      SingerId   BIGINT PRIMARY KEY,
      FirstName  VARCHAR(1024),
      LastName   VARCHAR(1024),
      SingerInfo BYTEA,
      BirthDate  TIMESTAMPTZ
    );
    

    After you create the Singers table, click refreshRefresh to update your database schema.

Required roles and permissions

To get the permissions that you need to complete the tasks in this document, ask your administrator to grant you the Cloud SQL Admin (roles/cloudsql.admin) IAM role on the project. For more information about granting roles, see Manage access to projects, folders, and organizations.

You might also be able to get the required permissions through custom roles or other predefined roles.

You also need the cloudaicompanion.companions.generateChat permission to use explain SQL statements in the query editor and cloudaicompanion.companions.generateCode to use help me code.

Generate SQL queries using natural language prompts

As an early-stage technology, Gemini for Google Cloud products can generate output that seems plausible but is factually incorrect. We recommend that you validate all output from Gemini for Google Cloud products before you use it. For more information, see Gemini for Google Cloud and responsible AI.

You can give Gemini natural language comments (or prompts) to generate queries that are based on your schema. For example, you can prompt Gemini to generate SQL in response to the following prompts:

If your schema changes, such as addition of a new table or column, then click refreshRefresh to update your schema before using Gemini.

Note: When you enter a prompt for Gemini in Cloud SQL, information about your database's schema is included with the prompt. This metadata can include table and column names, data types, and column descriptions. Your database data remains in Cloud SQL and isn't sent to Gemini.

To generate SQL in Cloud SQL with Gemini assistance, follow these steps:

  1. In the Google Cloud console, go to the Cloud SQL page.

    Go to Cloud SQL

  2. Select an instance from the list.

  3. In the navigation menu, click Cloud SQL Studio.

  4. Sign in to Cloud SQL Studio using the name of your database, username, and password. The Explorer pane displays a list of objects in your database.

  5. In the taskbar, click pen_sparkarrow_drop_downGemini to view Gemini features in Cloud SQL.

  6. Ensure that Comment-to-query generation is enabled.

  7. To query your database, click add New SQL editor tab.

  8. To generate SQL, type a comment in the query editor starting with -- followed by a single-line comment, and then press Return or Enter.

    For example, enter the following prompt:

    -- add a row to table singers
    

    Press Return or Enter. Gemini generates SQL that's similar to the following:

    INSERT INTO Singers (SingerId, FirstName, LastName, BirthDate)
    VALUES (1, 'Alex', 'M.', '1977-10-16');
    

    To continue the example using the Singers table, enter the following prompt:

    -- show all singers born in the 70s
    

    Gemini generates SQL that's similar to the following:

    SELECT *
    FROM Singers
    WHERE Singers.BirthDate
    BETWEEN '1970-01-01' AND '1979-12-31'
    
    
    Note: Gemini might suggest different queries each time that you enter the same prompt.
  9. Review the SQL suggestion and take any of the following actions:

    Caution: Because Data Manipulation Language (DML) and Data Definition Language (DDL) queries generated by Gemini can overwrite data, we recommend that you validate the generated queries before you run the queries.
Help me code tool

To use the Help me code tool, follow these steps:

  1. In the Google Cloud console, go to the Cloud SQL page.

    Go to Cloud SQL

  2. Select an instance from the list.

  3. In the navigation menu, click Cloud SQL Studio.

  4. Sign in to Cloud SQL Studio using the name of your database, username, and password. The Explorer pane displays a list of objects in your database.

  5. To query your database, click the add New tab.

  6. Click pen_spark Help me code next to the query editor.

  7. In the Help me code window, enter a prompt. For example, add a row to table singers and click Generate.

    Gemini generates SQL that's similar to the following:

    INSERT INTO Singers (SingerId, FirstName, LastName, BirthDate)
    VALUES (1, Alex, 'M.', '1977-10-16');
    
    Note: Gemini might suggest different syntax each time that you enter the same prompt.
  8. Review the generated SQL and take any of the following actions:

    Caution: Because Data Manipulation Language (DML) and Data Definition Language (DDL) queries generated by Gemini can overwrite data, we recommend that you validate the generated queries before you run the queries.
Explain SQL statements in the query editor

You can use Gemini in Cloud SQL to explain SQL queries in natural language. This explanation can help you understand the syntax, underlying schema, and business context for complex or long queries.

  1. In the Google Cloud console, go to the Cloud SQL page.

    Go to Cloud SQL

  2. Select an instance from the list.

  3. In the navigation menu, click Cloud SQL Studio.

  4. Sign in to Cloud SQL Studio using the name of your database, username, and password. The Explorer pane displays a list of objects in your database.

  5. To query your database, click the add New tab.

  6. In the query editor, paste the query you want explained.

  7. Highlight the query that you want Gemini to explain, and then click spark Explain this query.

    The explanation for the SQL query appears in the Gemini Chat window.

What's next

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-11 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-07-11 UTC."],[],[]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4