# EXEC

> EXEC in StackQL: call a provider resource method directly, with query hints to return results or await completion, such as starting or stopping an instance.

Source: https://stackql.io/language-spec/exec

Executes a provider resource method (built in procedure).  

See also:  
[[ StackQL Resource Hierarchy ]](/getting-started/resource-hierarchy)

* * * 

## Syntax

*execStatement::=*

&nbsp;  
&nbsp;

```sql
EXEC [ queryHint ] <multipartIdentifier>.<methodName> [ <methodArguments> ];
```

## Query Hints

Query hints supported for the `EXEC` command are summarised below:  

| Hint                 | Description                                                                                                                                                                |
|----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `/*+ SHOWRESULTS */` | Returns result set, designed for methods that return data, use `SELECT` however if possible.                                                                               |
| `/*+ AWAIT  */`      | Makes the operation blocking (synchronous), provides script control for long running operations (e.g. mutation operations).  Note: this is not supported for all providers |

* * *

## Examples

### Stopping a Google Compute Engine instance
Run an `EXEC` statement to stop a running Compute Engine instance in an authenticated session.

```sql
-- Stop a running Compute Engine resource instance
EXEC google.compute.instances.stop 
@instance = 'demo-instance-1', 
@project = 'stackql-demo', 
@zone = 'australia-southeast1-a';
```

### Starting a Google Compute Engine instance (synchronous option)
Run an `EXEC` statement to start a stopped Compute Engine instance in an authenticated session, uses the `/*+ AWAIT  */` query hint to make the operation blocking (synchronous).

```sql
-- Start a stopped Compute Engine resource instance
EXEC /*+ AWAIT  */ google.compute.instances.stop 
@instance = 'demo-instance-1', 
@project = 'stackql-demo', 
@zone = 'australia-southeast1-a';
```

### Starting and stopping an AWS EC2 instance
Run an `EXEC` statement to start an AWS EC2 instance in an authenticated session.

```sql
-- Start an EC2 instance
EXEC aws.ec2.instances.start_instances 
@InstanceId = 'i-0fc989cf4efcd8b88', 
@region = 'ap-southeast-2';
-- Stop an EC2 instance
EXEC aws.ec2.instances.stop_instances 
@InstanceId = 'i-0fc989cf4efcd8b88', 
@region = 'ap-southeast-2';
```

### Attach a Disk to a Google Compute Engine instance
Run an `EXEC` statement to attach a Disk to a Compute Engine instance in an authenticated session.

```sql
-- Attach a Disk resource to a Compute Engine instance
EXEC google.compute.instances.attachDisk 
@zone='australia-southeast1-a', 
@project='stackql-demo', 
@instance='demo-instance-1' 
@@json=
'{
"source": "projects/stackql-demo/zones/australia-southeast1-a/disks/test10gbdisk2", 
"boot": false 
}';
```

### Simulate Azure Spot VM eviction
Run an `EXEC` statement to simulate eviction of Azure Spot VM Instance. 

```sql
exec azure.compute.virtual_machines.simulate_eviction
@subscription_id = '0123456789',
@resource_group_name = 'vmss-flex',
@vm_name = 'vmss-flex-manual-1';
```
