Additional Functionalities for Temporary Tables

1C Developer team

03.05.2024 5 min

Adding Data to Existing Temporary Tables

As you know, temporary tables in 1C:Enterprise are created using a query with the INTO clause following the SELECT statement. The temporary table's name comes after INTO, and its structure is defined by the query itself.

This query

SELECT

    Products.Code AS Code,

    Products.Name AS Name   

INTO TempTable_Items

FROM

    Catalog.Products AS Products

;

will create a temporary table named TempTable_Items with fields Code and Name.
It is not possible to add data to an already created temporary table. If we try to add the contents of the Services catalog to TempTable_Items, we will get an error "Temporary table already exists".

SELECT

    Products.Code AS Code,

    Products.Name AS Name  

INTO TempTable_Items

FROM

    Catalog.Products AS Products

;

SELECT

    Services.Code AS Code,

    Services.Name AS Name

INTO TempTable_Items

FROM

    Catalog.Services AS Services

;


Version 8.3.25 introduced the ADD statement as a new feature for adding data to existing temporary tables.

SELECT

    Products.Code AS Code,

    Products.Name AS Name   

INTO TempTable_Items

FROM

    Catalog.Products AS Products

;

SELECT

    Services.Code AS Code,

    Services.Name AS Name   

APPEND TO TempTable_Items

FROM

    Catalog.Services AS Services

;


When adding data to an existing temporary table, the structure of the query (including column names and data types) must exactly match the structure of the table. Otherwise, the platform will display the error message "The structure of the existing temporary table does not match the structure of the data being added".

This functionality of adding data to existing temporary tables can be beneficial in several ways. It can help reduce the number of redundant "similar" temporary tables used within a single query, improving the readability of the query itself and potentially making its execution more efficient.

Creating Multiple Indexes for Temporary Tables

Temporary tables will now support the creation of multiple indexes to enhance search performance. The INDEX BY statement will be extended with the SETS clause to enable this:

INDEX BY SETS ((FieldSet1)[ ,(FieldSet2)[,…]])

Example:

SELECT

    Products.Code AS Code,

    Products.Name AS Name,

    Products.SKU AS SKU

INTO TempTable_Items

FROM

    Catalog.Products AS Products

INDEX BY SETS (

    (Code, Name),

    (SKU)

)


Two indexes will be created in the temporary table TempTable_Items: one on two fields (Code, Name) and one on a single field (SKU).

Index creation will only be possible during the initial insertion of data into the temporary table.

Unique Indexes on Temporary Tables

The UNIQUE option has been introduced for the INDEX BY statements. When used, it will create a unique index.

SELECT

    Products.Code AS Code,

    Products.Name AS Name,

    Products.SKU AS SKU

INTO TempTable

FROM

    Catalog.Products AS Products

INDEX BY SETS (

    (Code, Name) UNIQUE,

    (SKU)

)


The 1C:Enterprise language has been upgraded to support some new features for working with temporary tables. We've also made improvements to the query wizard to make it easier to use these features.

We hope these enhancements will help you get even more out of temporary tables, which are already a powerful tool in your 1C:Enterprise toolbox.

 

Be the first to know tips & tricks on business application development!

A confirmation e-mail has been sent to the e-mail address you provided .

Click the link in the e-mail to confirm and activate the subscription.