1. Packages
  2. MSSQL
  3. API Docs
  4. getQuery
Microsoft SQL Server v0.0.8 published on Wednesday, Nov 1, 2023 by pulumiverse

mssql.getQuery

Explore with Pulumi AI

mssql logo
Microsoft SQL Server v0.0.8 published on Wednesday, Nov 1, 2023 by pulumiverse

    Retrieves arbitrary SQL query result.

    Note This data source is meant to be an escape hatch for all cases not supported by the provider’s data sources. Whenever possible, use dedicated data sources, which offer better plan, validation and error reporting.

    Example Usage

    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Mssql = Pulumi.Mssql;
    
    return await Deployment.RunAsync(() => 
    {
        var test = Mssql.GetDatabase.Invoke(new()
        {
            Name = "test",
        });
    
        var column = Mssql.GetQuery.Invoke(new()
        {
            DatabaseId = test.Apply(getDatabaseResult => getDatabaseResult.Id),
            Query = "SELECT [column_id], [name] FROM sys.columns WHERE [object_id] = OBJECT_ID('test_table')",
        });
    
        return new Dictionary<string, object?>
        {
            ["columnNames"] = column.Apply(getQueryResult => getQueryResult.Results).Select(__item => __item.Name).ToList(),
        };
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    	"github.com/pulumiverse/pulumi-mssql/sdk/go/mssql"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		test, err := mssql.LookupDatabase(ctx, &mssql.LookupDatabaseArgs{
    			Name: "test",
    		}, nil)
    		if err != nil {
    			return err
    		}
    		column, err := mssql.GetQuery(ctx, &mssql.GetQueryArgs{
    			DatabaseId: test.Id,
    			Query:      "SELECT [column_id], [name] FROM sys.columns WHERE [object_id] = OBJECT_ID('test_table')",
    		}, nil)
    		if err != nil {
    			return err
    		}
    		var splat0 []string
    		for _, val0 := range column.Results {
    			splat0 = append(splat0, val0.Name)
    		}
    		ctx.Export("columnNames", splat0)
    		return nil
    	})
    }
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.mssql.MssqlFunctions;
    import com.pulumi.mssql.inputs.GetDatabaseArgs;
    import com.pulumi.mssql.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 = MssqlFunctions.getDatabase(GetDatabaseArgs.builder()
                .name("test")
                .build());
    
            final var column = MssqlFunctions.getQuery(GetQueryArgs.builder()
                .databaseId(test.applyValue(getDatabaseResult -> getDatabaseResult.id()))
                .query("SELECT [column_id], [name] FROM sys.columns WHERE [object_id] = OBJECT_ID('test_table')")
                .build());
    
            ctx.export("columnNames", column.applyValue(getQueryResult -> getQueryResult.results()).stream().map(element -> element.name()).collect(toList()));
        }
    }
    
    import pulumi
    import pulumi_mssql as mssql
    
    test = mssql.get_database(name="test")
    column = mssql.get_query(database_id=test.id,
        query="SELECT [column_id], [name] FROM sys.columns WHERE [object_id] = OBJECT_ID('test_table')")
    pulumi.export("columnNames", [__item["name"] for __item in column.results])
    
    import * as pulumi from "@pulumi/pulumi";
    import * as mssql from "@pulumi/mssql";
    
    const test = mssql.getDatabase({
        name: "test",
    });
    const column = test.then(test => mssql.getQuery({
        databaseId: test.id,
        query: "SELECT [column_id], [name] FROM sys.columns WHERE [object_id] = OBJECT_ID('test_table')",
    }));
    export const columnNames = column.then(column => column.results.map(__item => __item.name));
    

    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(database_id: Optional[str] = None,
                  query: Optional[str] = None,
                  opts: Optional[InvokeOptions] = None) -> GetQueryResult
    def get_query_output(database_id: Optional[pulumi.Input[str]] = None,
                  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)
    // Output-based functions aren't available in Java yet
    
    fn::invoke:
      function: mssql:index/getQuery:getQuery
      arguments:
        # arguments dictionary

    The following arguments are supported:

    DatabaseId string
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>').
    Query string
    SQL query returning single result set, with any number of rows, where all columns are strings
    DatabaseId string
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>').
    Query string
    SQL query returning single result set, with any number of rows, where all columns are strings
    databaseId String
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>').
    query String
    SQL query returning single result set, with any number of rows, where all columns are strings
    databaseId string
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>').
    query string
    SQL query returning single result set, with any number of rows, where all columns are strings
    database_id str
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>').
    query str
    SQL query returning single result set, with any number of rows, where all columns are strings
    databaseId String
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>').
    query String
    SQL query returning single result set, with any number of rows, where all columns are strings

    getQuery Result

    The following output properties are available:

    DatabaseId string
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>').
    Id string
    Query string
    SQL query returning single result set, with any number of rows, where all columns are strings
    Results List<ImmutableDictionary<string, string>>
    Results of the SQL query, represented as list of maps, where the map key corresponds to column name and the value is the value of column in given row.
    DatabaseId string
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>').
    Id string
    Query string
    SQL query returning single result set, with any number of rows, where all columns are strings
    Results []map[string]string
    Results of the SQL query, represented as list of maps, where the map key corresponds to column name and the value is the value of column in given row.
    databaseId String
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>').
    id String
    query String
    SQL query returning single result set, with any number of rows, where all columns are strings
    results List<Map<String,String>>
    Results of the SQL query, represented as list of maps, where the map key corresponds to column name and the value is the value of column in given row.
    databaseId string
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>').
    id string
    query string
    SQL query returning single result set, with any number of rows, where all columns are strings
    results {[key: string]: string}[]
    Results of the SQL query, represented as list of maps, where the map key corresponds to column name and the value is the value of column in given row.
    database_id str
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>').
    id str
    query str
    SQL query returning single result set, with any number of rows, where all columns are strings
    results Sequence[Mapping[str, str]]
    Results of the SQL query, represented as list of maps, where the map key corresponds to column name and the value is the value of column in given row.
    databaseId String
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>').
    id String
    query String
    SQL query returning single result set, with any number of rows, where all columns are strings
    results List<Map<String>>
    Results of the SQL query, represented as list of maps, where the map key corresponds to column name and the value is the value of column in given row.

    Package Details

    Repository
    mssql pulumiverse/pulumi-mssql
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the mssql Terraform Provider.
    mssql logo
    Microsoft SQL Server v0.0.8 published on Wednesday, Nov 1, 2023 by pulumiverse