Search code examples
google-cloud-spanner

Insert Statement providing the following error in google cloud spanner


When tried to insert this data i am getting the following error. Not sure what i am missing but looks silly...

Table Structure

CREATE TABLE PackageItems ( ItemID INT64 NOT NULL, LocationID INT64 NOT NULL, PackageID STRING(MAX) NOT NULL, Price FLOAT64 NOT NULL, OrganizationID INT64, CreatedBy STRING(MAX), CreatedDateTime TIMESTAMP OPTIONS (allow_commit_timestamp=true), LastModifiedBy STRING(MAX), LastModifiedDateTime TIMESTAMP OPTIONS (allow_commit_timestamp=true), ) PRIMARY KEY (OrganizationID, LocationID, PackageID, ItemID);

Insert Command INSERT INTO PackageItems (ItemID, LocationID, PackageID, Price, OrganizationID) (5,1,"1",12.50,1635931867921)

Error Syntax error: Unexpected integer literal "5" at line 6, column 2


Solution

  • It seems that you are missing the VALUES keyword in your insert string:

    So instead of:

    INSERT INTO PackageItems (ItemID, LocationID, PackageID, Price, OrganizationID) 
    (5,1,"1",12.50,1635931867921)
    

    Try:

    INSERT INTO PackageItems (ItemID, LocationID, PackageID, Price, OrganizationID) 
    VALUES (5,1,'1',12.50,1635931867921)
    

    (Also note the change from "1" to '1' for the string literal.)