Skip to content

gcp run-sql

Run SQL Query

Description

run sql query in google cloud sql with MySQL, PostgreSQL, or SQL Server instance

Synopsis

gcp run-sql
    [--site <site>]
    --host <host>
    <query>

Arguments

site - (string)

     Site where this command will be executed
     Example: --site "site-1"
     Default: input.site      Attributes: optional

host - (string)

     Enter Instance Id
     Example: --host "host-1"
     Default: _None_      Attributes: required

query - (string)

     Sql Query
     Example: "select * from accounts"
     Default: _None_      Attributes: required

Examples

Input:

!gcp run-sql   "select * from testTable;" --host "test-id"
Output:
id  name    something   
 1  test1   name1       
 2  test2   name2       
 3  test3   name3       
 4  test4   name4       
 5  test5   name5       
 6  test6   name6       
Input:
!gcp run-sql   "select * from test_name;" --host "test-user1"
Output:
id  name        uhyt    
 1  fdffdgb1    gfbhdf1 
 2  fdffdgb2    gfbhdf2 
 3  fdffdgb3    gfbhdf3 
 4  fdffdgb4    gfbhdf4 
 5  fdffdgb5    gfbhdf5 
Input:
!gcp run-sql   "select * from table_name;" --host "test-user"
Output:
id      name            something                   
789456  sdfsafsda       value3,...valueN            
789457  sdfsdfsafsda    valufdvsde3,...valueN       
789458  fdssdfsdfsafsda fdsvalufdvsde3,...valueN    

Access Control

To use this command, you need access to the following:

Field Value
Action "read"
Service Type "gcp"
Service Instance
Namespace
Object Type
Object ID

Please see Access Control for details.