Image = "https://hut.openintegrations.dev/test_data/picture.jpg"; OPI_TypeConversion.GetBinaryData(Image); // Image - Type: BinaryData Address = "127.0.0.1"; Login = "bayselonarrend"; Password = "12we..."; Base = "test_data"; TLS = True; Port = 5432; Options = New Structure; Options.Insert("addr" , Address); Options.Insert("db" , Base); Options.Insert("login", Login); Options.Insert("pass" , Password); Options.Insert("port" , Port); ConnectionString = OPI_TestDataRetrieval.ExecuteTestCLI("postgres", "GenerateConnectionString", Options); If TLS Then Options = New Structure; Options.Insert("trust", True); TLSSettings = OPI_TestDataRetrieval.ExecuteTestCLI("postgres", "GetTLSSettings", Options); Else TLSSettings = Undefined; EndIf; Connection = OPI_PostgreSQL.CreateConnection(ConnectionString, TLSSettings); // CREATE QueryText = " |CREATE TABLE test_table ( |id SERIAL PRIMARY KEY, |name NAME, |age INT, |salary REAL, |is_active BOOL, |created_at DATE, |data BYTEA |);"; Options = New Structure; Options.Insert("sql", QueryText); Options.Insert("dbc", Connection); Result = OPI_TestDataRetrieval.ExecuteTestCLI("postgres", "ExecuteSQLQuery", Options); // INSERT with parameters QueryText = " |INSERT INTO test_table (name, age, salary, is_active, created_at, data) |VALUES ($1, $2, $3, $4, $5, $6);"; ParameterArray = New Array; ParameterArray.Add(New Structure("NAME" , "Vitaly")); ParameterArray.Add(New Structure("INT" , 25)); ParameterArray.Add(New Structure("REAL" , 1000.12)); ParameterArray.Add(New Structure("BOOL" , True)); ParameterArray.Add(New Structure("DATE" , OPI_Tools.GetCurrentDate())); ParameterArray.Add(New Structure("BYTEA", Image)); Options = New Structure; Options.Insert("sql" , QueryText); Options.Insert("params", ParameterArray); Options.Insert("dbc" , Connection); Result = OPI_TestDataRetrieval.ExecuteTestCLI("postgres", "ExecuteSQLQuery", Options); // SELECT (The result of this query is shown in the Result block) QueryText = "SELECT id, name, age, salary, is_active, created_at, data FROM test_table;"; Options = New Structure; Options.Insert("sql", QueryText); Options.Insert("dbc", Connection); Result = OPI_TestDataRetrieval.ExecuteTestCLI("postgres", "ExecuteSQLQuery", Options); // DO + Transaction QueryText = "DO $$ |BEGIN | CREATE TABLE users ( | id SMALLSERIAL, | name TEXT NOT NULL, | age INT NOT NULL | ); | INSERT INTO users (name, age) VALUES ('Alice', 30); | INSERT INTO users (name, age) VALUES ('Bob', 25); | INSERT INTO users (name, age) VALUES ('Charlie', 35); |END $$ LANGUAGE plpgsql;"; Options = New Structure; Options.Insert("sql", QueryText); Options.Insert("dbc", Connection); Result = OPI_TestDataRetrieval.ExecuteTestCLI("postgres", "ExecuteSQLQuery", Options); // SQL query from file SQLFile = "https://hut.openintegrations.dev/test_data/TEST_DATA.sql"; // Binary Data, URL or path to file Options = New Structure; Options.Insert("sql", SQLFile); Options.Insert("dbc", Connection); Result = OPI_TestDataRetrieval.ExecuteTestCLI("postgres", "ExecuteSQLQuery", Options); Closing = OPI_PostgreSQL.CloseConnection(Connection);