> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://learning.postman.com/llms.txt. For full content including API reference and SDK examples, see https://learning.postman.com/llms-full.txt.

# Manage and use datasets in scripts

The `pm.datasets` function provides access to datasets from a script or [local mock server](/docs/design-apis/mock-apis/local-mock-servers). You can query datasets using SQL to retrieve data at runtime. This enables your scripts and mock servers to return dynamic, data-driven responses instead of static values. All methods are asynchronous and return Promises, so use `await` to access their results.

Learn more about [testing with datasets](/docs/tests-and-scripts/datasets/overview).

<Note>
  The `pm.datasets` function is supported only in Local View in the Postman desktop app.
</Note>

## pm.datasets

The `pm.datasets` function provides access to datasets from a script or local mock server. You can load a dataset by its ID and then use various methods to manipulate and query the dataset.

### pm.datasets(datasetId:String)

Loads a dataset and returns a handle you can use to interact with the dataset.

```js
const ds = pm.datasets('menu-id');
```

### dataset.executeView(viewId:String, params:Object)

Runs a view that's already defined in the dataset and returns the results.

```js
const ds = pm.datasets('menu-id');

const result = await ds.executeView('view-id', { category: 'pizza' });

return {
  items: result.rows
};
```

### dataset.executeQuery(sql:String, params:Object)

Runs a custom SQL query against the dataset and returns the results.

```js
const ds = pm.datasets('menu-id');

const result = await ds.executeQuery(
  'SELECT * FROM menu WHERE category = ?',
  ['pizza']
);

return {
  items: result.rows
};
```

### dataset.addView(options:Object)

Creates a reusable SQL view on the dataset.

```js
const ds = pm.datasets('menu-id');

await ds.addView({
  name: 'expensive_items',
  sql: 'SELECT * FROM menu WHERE price > 15'
});
```

### dataset.removeView(viewId:String)

Removes a view from the dataset.

```js
const ds = pm.datasets('menu-id');

await ds.removeView('view-id');
```