Ensure table
Creates a new table if it does not exist or updates the composition of columns in an existing table
- Parameters
- Advanced call ?
Function EnsureTable(Val Table, Val ColoumnsStruct, Val Connection = "", Val Tls = "") Export
| Parameter | CLI option | Type | Required | Description |
|---|---|---|---|---|
| Table | --table | String | ✔ | Table name |
| ColoumnsStruct | --cols | Structure Of KeyAndValue | ✔ | Column structure: Key > Name, Value > Data type |
| Connection | --dbc | String, Arbitrary | ✖ | Existing connection or database path |
| Tls | --tls | Structure Of KeyAndValue | ✖ | TLS settings, if necessary. See GetTlsSettings |
Returns
Map Of KeyAndValue - Result of query execution
| Parameter | Description |
|---|---|
| addin_mode | Manual selection of external component connection mode (for 1C): Isolated, NotIsolated |
| dontwait | Creates a background job and returns its data (for 1C and OneScript only) |
tip
As a result of changing the table structure, data may be lost! It is recommended to test this method on test data beforehand
This function does not update the data type of existing columns
1C:Enterprise/OneScript code example
Address = "127.0.0.1";
Login = "bayselonarrend";
Password = "12we...";
Base = "testbase1";
TLS = True;
Port = 5432;
ConnectionString = OPI_PostgreSQL.GenerateConnectionString(Address, Base, Login, Password, Port);
If TLS Then
TLSSettings = OPI_PostgreSQL.GetTLSSettings(True);
Else
TLSSettings = Undefined;
EndIf;
Table = "testtable";
ColoumnsStruct = New Structure;
ColoumnsStruct.Insert("smallint_field" , "SMALLINT");
ColoumnsStruct.Insert("uuid_field" , "uuid");
ColoumnsStruct.Insert("bigint_field" , "BIGINT");
ColoumnsStruct.Insert("custom_field" , "TEXT");
Result = OPI_PostgreSQL.EnsureTable(Table, ColoumnsStruct, ConnectionString, TLSSettings);
- Bash
- CMD/Bat
# JSON data can also be passed as a path to a .json file
oint postgres EnsureTable \
--table "test_new" \
--cols "{'smallint_field':'SMALLINT','uuid_field':'uuid','bigint_field':'BIGINT','custom_field':'TEXT'}" \
--dbc "postgresql://bayselonarrend:***@127.0.0.1:5432/" \
--tls "{'use_tls':true,'accept_invalid_certs':true}"
:: JSON data can also be passed as a path to a .json file
oint postgres EnsureTable ^
--table "test_new" ^
--cols "{'smallint_field':'SMALLINT','uuid_field':'uuid','bigint_field':'BIGINT','custom_field':'TEXT'}" ^
--dbc "postgresql://bayselonarrend:***@127.0.0.1:5432/" ^
--tls "{'use_tls':true,'accept_invalid_certs':true}"
Result
{
"result": true,
"commit": {
"result": true
}
}