Executing Postgres-SQL Stored procedures from Azure-CLI/Azure-DevOps pipelines

Guna Sekhar Chukka 0 Reputation points
2023-01-27T05:43:17.53+00:00

We are using postgres flexi server for Data-base operations, in this we need to perform some operations on database Functions from remote service i:e; AZ-CLI/AZ-DevOps pipelines.

What is the probable command to call the postgres-SQL stored procedure functions?

 -c 'CALL slb."sp_${{ parameters.service }}StartUp"()';
Azure Database for PostgreSQL
{count} votes

1 answer

Sort by: Most helpful
  1. Roderick Bant 2,056 Reputation points
    2023-01-27T09:30:39.3266667+00:00

    Hi, thank you for your question at Q&A. I hope you are doing well. I understand that you want to interact with a Flexible Postgres database with Azure CLI from an Azure DevOps Pipeline.

    In your pipeline you can use the AzureCLI@2 task to use Azure CLI in your pipeline. Using the task you can then run the az postgres flexible-server connect command to execute queries on the flexible server instance. More info on the command can be found here

    The yaml for such a pipeline task may look like below:

    - task: AzureCLI@2
      name: queryPostgresDb
      inputs:
        azureSubscription: "myAzureResourceManagerServiceConnection"
        scriptType: 'bash'
        scriptLocation: 'inlineScript'
        inlineScript: >
          az postgres flexible-server connect
            --name my-flex-postgres-server 
            --database-name mydb
            --querytext 'SELECT * FROM mytable;'
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.