Skip to main content

Ensure table

Creates a new table if it does not exist or updates the composition of columns in an existing table

Function EnsureTable(Val Table, Val ColoumnsStruct, Val Connection = "", Val Tls = "") Export

ParameterCLI optionTypeRequiredDescription
Table--tableStringTable name
ColoumnsStruct--colsStructure Of KeyAndValueColumn structure: Key > Name, Value > Data type
Connection--dbcString, ArbitraryExisting connection or database path
Tls--tlsStructure Of KeyAndValueTLS settings, if necessary. See GetTlsSettings

Returns: Map Of KeyAndValue - Result of query execution


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";
Table = "testtable";

ConnectionString = OPI_PostgreSQL.GenerateConnectionString(Address, Base, Login, Password);

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);
    # 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/"
Result
{
"result": true,
"commit": {
"result": true
}
}