1. Packages
  2. Sql Provider
  3. API Docs
  4. getQuery
sql 0.5.0 published on Monday, Apr 14, 2025 by paultyng

sql.getQuery

Explore with Pulumi AI

sql logo
sql 0.5.0 published on Monday, Apr 14, 2025 by paultyng

    The sql.getQuery datasource allows you to execute a SQL query against the database of your choice.

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as sql from "@pulumi/sql";
    
    const test = sql.getQuery({
        query: "select 1 as number, 'foo' as string",
    });
    // The number column in this case is a Terraform "Number" type
    // so you can use it as such:
    const myMath = test.then(test => 1 + test.results?.[0]?.number);
    export const math = myMath;
    
    import pulumi
    import pulumi_sql as sql
    
    test = sql.get_query(query="select 1 as number, 'foo' as string")
    # The number column in this case is a Terraform "Number" type
    # so you can use it as such:
    my_math = 1 + test.results[0]["number"]
    pulumi.export("math", my_math)
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-terraform-provider/sdks/go/sql/sql"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		test, err := sql.GetQuery(ctx, &sql.GetQueryArgs{
    			Query: "select 1 as number, 'foo' as string",
    		}, nil)
    		if err != nil {
    			return err
    		}
    		// The number column in this case is a Terraform "Number" type
    		// so you can use it as such:
    		myMath := 1 + test.Results[0].Number
    		ctx.Export("math", myMath)
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Sql = Pulumi.Sql;
    
    return await Deployment.RunAsync(() => 
    {
        var test = Sql.GetQuery.Invoke(new()
        {
            Query = "select 1 as number, 'foo' as string",
        });
    
        // The number column in this case is a Terraform "Number" type
        // so you can use it as such:
        var myMath = 1 + test.Apply(getQueryResult => getQueryResult.Results[0]?.Number);
    
        return new Dictionary<string, object?>
        {
            ["math"] = myMath,
        };
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.sql.SqlFunctions;
    import com.pulumi.sql.inputs.GetQueryArgs;
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Map;
    import java.io.File;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    
    public class App {
        public static void main(String[] args) {
            Pulumi.run(App::stack);
        }
    
        public static void stack(Context ctx) {
            final var test = SqlFunctions.getQuery(GetQueryArgs.builder()
                .query("select 1 as number, 'foo' as string")
                .build());
    
            // The number column in this case is a Terraform "Number" type
            // so you can use it as such:
            final var myMath = 1 + test.applyValue(getQueryResult -> getQueryResult.results()[0].number());
    
            ctx.export("math", myMath);
        }
    }
    
    Coming soon!
    

    Using getQuery

    Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.

    function getQuery(args: GetQueryArgs, opts?: InvokeOptions): Promise<GetQueryResult>
    function getQueryOutput(args: GetQueryOutputArgs, opts?: InvokeOptions): Output<GetQueryResult>
    def get_query(query: Optional[str] = None,
                  opts: Optional[InvokeOptions] = None) -> GetQueryResult
    def get_query_output(query: Optional[pulumi.Input[str]] = None,
                  opts: Optional[InvokeOptions] = None) -> Output[GetQueryResult]
    func GetQuery(ctx *Context, args *GetQueryArgs, opts ...InvokeOption) (*GetQueryResult, error)
    func GetQueryOutput(ctx *Context, args *GetQueryOutputArgs, opts ...InvokeOption) GetQueryResultOutput

    > Note: This function is named GetQuery in the Go SDK.

    public static class GetQuery 
    {
        public static Task<GetQueryResult> InvokeAsync(GetQueryArgs args, InvokeOptions? opts = null)
        public static Output<GetQueryResult> Invoke(GetQueryInvokeArgs args, InvokeOptions? opts = null)
    }
    public static CompletableFuture<GetQueryResult> getQuery(GetQueryArgs args, InvokeOptions options)
    public static Output<GetQueryResult> getQuery(GetQueryArgs args, InvokeOptions options)
    
    fn::invoke:
      function: sql:index/getQuery:getQuery
      arguments:
        # arguments dictionary

    The following arguments are supported:

    Query string
    The query to execute. The types in this query will be reflected in the typing of the result attribute.
    Query string
    The query to execute. The types in this query will be reflected in the typing of the result attribute.
    query String
    The query to execute. The types in this query will be reflected in the typing of the result attribute.
    query string
    The query to execute. The types in this query will be reflected in the typing of the result attribute.
    query str
    The query to execute. The types in this query will be reflected in the typing of the result attribute.
    query String
    The query to execute. The types in this query will be reflected in the typing of the result attribute.

    getQuery Result

    The following output properties are available:

    Id string
    This attribute is only present for some compatibility issues and should not be used. It will be removed in a future version.

    Deprecated: Deprecated

    Query string
    The query to execute. The types in this query will be reflected in the typing of the result attribute.
    Results List<object>
    The result of the query. This will be a list of objects. Each object will have attributes with names that match column names and types that match column types. The exact translation of types is dependent upon the database driver.
    Id string
    This attribute is only present for some compatibility issues and should not be used. It will be removed in a future version.

    Deprecated: Deprecated

    Query string
    The query to execute. The types in this query will be reflected in the typing of the result attribute.
    Results []interface{}
    The result of the query. This will be a list of objects. Each object will have attributes with names that match column names and types that match column types. The exact translation of types is dependent upon the database driver.
    id String
    This attribute is only present for some compatibility issues and should not be used. It will be removed in a future version.

    Deprecated: Deprecated

    query String
    The query to execute. The types in this query will be reflected in the typing of the result attribute.
    results List<Object>
    The result of the query. This will be a list of objects. Each object will have attributes with names that match column names and types that match column types. The exact translation of types is dependent upon the database driver.
    id string
    This attribute is only present for some compatibility issues and should not be used. It will be removed in a future version.

    Deprecated: Deprecated

    query string
    The query to execute. The types in this query will be reflected in the typing of the result attribute.
    results any[]
    The result of the query. This will be a list of objects. Each object will have attributes with names that match column names and types that match column types. The exact translation of types is dependent upon the database driver.
    id str
    This attribute is only present for some compatibility issues and should not be used. It will be removed in a future version.

    Deprecated: Deprecated

    query str
    The query to execute. The types in this query will be reflected in the typing of the result attribute.
    results Sequence[Any]
    The result of the query. This will be a list of objects. Each object will have attributes with names that match column names and types that match column types. The exact translation of types is dependent upon the database driver.
    id String
    This attribute is only present for some compatibility issues and should not be used. It will be removed in a future version.

    Deprecated: Deprecated

    query String
    The query to execute. The types in this query will be reflected in the typing of the result attribute.
    results List<Any>
    The result of the query. This will be a list of objects. Each object will have attributes with names that match column names and types that match column types. The exact translation of types is dependent upon the database driver.

    Package Details

    Repository
    sql paultyng/terraform-provider-sql
    License
    Notes
    This Pulumi package is based on the sql Terraform Provider.
    sql logo
    sql 0.5.0 published on Monday, Apr 14, 2025 by paultyng