# create\_postgresql\_connection

`create_postgresql_connection` function has 1 variants:

{% tabs %}
{% tab title="Variant 1" %}

#### Description <a href="#description" id="description"></a>

1. &#x20;`create_postgresql_connection` creates a new named connection if it does not exist.
2. If connection fails, `create_postgresql_connection` returns error messages as character string. If connection exists, does nothing.
3. This function can be called in any phase of execution, however it is advised to be called in ["connection\_not\_found" trigger](https://sodium.gitbook.io/sodium/language-reference/built-in-triggers/session-level-triggers/connection_not_found-trigger) or in user login page.

#### Declaration <a href="#declaration" id="declaration"></a>

```
char create_postgresql_connection(char connectionName, char instanceName, char userName, char userPassword);
```

#### Parameters <a href="#parameters" id="parameters"></a>

* `char connectionName` - unique name to identify this connection in web session
* `char instanceName` Database instance name
* `char userName` - database login user name
* `char userPassword` database login password

#### Return Value <a href="#return-value" id="return-value"></a>

Nothing if connection has been made successfully. Otherwise, error text as string.

#### Example <a href="#example" id="example"></a>

```
void cb_oracle.logon2oracle() {
        char connResult;
        connResult = create_oracle_connection('default', :cb_oracle.tnsname, :cb_oracle.user, :cb_oracle.password);
        if (connResult is null) then
                show_page('oracle.frmx');
        else
                message('Error occured: ' || connResult);
        end if;
}
 
void cb_postgresql.logon2postgresql() {
    char connResult;
        connResult = create_postgresql_connection('default', :cb_postgresql.database, :cb_postgresql.user, :cb_postgresql.password);
    if (connResult is null) then
        show_page('postgresql.frmx');
        else
                message('Error occured: ' || connResult);
    end if;
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://muradkarakas.gitbook.io/sodium_documentation/language-reference/built-in-functions/sodium-built-in-functions/database-related-functions/create_postgresql_connection.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
