Search code examples
azureazure-cliazure-cli2

How do I specify the field types when using the Azure CLI entity insert command?


Does anyone know if there is a way to define the field types when using this Azure CLI 2.0 command

az storage entity insert . . . 

from a Windows Power Shell prompt?

When I use it, all of the fields get inserted into the table with a type of string.

The parameters, as documented here az storage entity insert , don't contain a way to explicitly state the method for defining the field types.

I'd like to be able to explicitly define the various field types for the non-string fields.

I've googled the above command a few ways and don't see any examples where folks are doing that.

I've tried inserting into an existing table where the fields and associated types already exist in other rows but the insert doesn't honor those values; probably because the types are attached to each row and not the table itself.

Also, I've tried inserting into a new table and the types aren't deduced (e.g., ...fieldname=false... is interpreted as a string and not a boolean.)

The Azure Storage Explorer will export rows. In the export, there are additional columns with the name structure of fieldname@type with values such as Edm.String,Edm.Boolean, etc. Using that structure, I've attempted to include those additional "fields" in the key=value pairs as a hint to the parser, but the call fails when I do that.

Without a way to define the types, this command seems only useful if all your field types are strings.


Solution

  • You can specify the type of the field by adding an additional pair of key-value in the form of field_name@odata.type=type_name.

    For example:

    az storage entity insert -c table_name -e PartitionKey=pk01 RowKey=1 Year=2018 [email protected]=Edm.Int32

    For your reference, here's the REST call under the hood: Reference: https://learn.microsoft.com/en-us/rest/api/storageservices/insert-entity.

    This has been tested in both bash and cmd.