Home > OS >  Type cast in PostgreSQL
Type cast in PostgreSQL

Time:10-23

if I have declared a variable using text data type, how do I typecast it to bigInt

please advise.

code is -

CREATE or REPLACE PROCEDURE "master_packs".procCheckUpdateAdd1("IMEI" text, battery_pack_number text) 
language 'plpgsql' AS
$BODY$
declare
retval text;

begin

    INSERT INTO "master_packs".list("serialNumber","assetName") VALUES("IMEI",battery_pack_number)
    
    ON CONFLICT DO NOTHING;
    update "master_packs".list SET "assetName" = battery_pack_number where "serialNumber" = "IMEI";
    -- update list SET "assetName" = "IMEI" where battery_pack_number = "assetName";
    
    
end;
$BODY$;

CAST "serialNumber" AS bigint;

PLEASE ADVICE.

CodePudding user response:

try this -

select Cast ('4632784672834673288' as bigint)

And read docs before doing anything...

https://www.postgresqltutorial.com/postgresql-cast/

CodePudding user response:

CREATE or REPLACE PROCEDURE "master_packs".procCheckUpdateAdd1("IMEI" text, battery_pack_number text) 
language 'plpgsql' AS
$BODY$
declare
retval text;

begin

    INSERT INTO "master_packs".list("serialNumber","assetName") VALUES("IMEI"::bigint,battery_pack_number)
    
    ON CONFLICT DO NOTHING;
    update "master_packs".list SET "assetName" = battery_pack_number where "serialNumber" = "IMEI"::bigint;
    -- update list SET "assetName" = "IMEI" where battery_pack_number = "assetName";
    
    
end;
$BODY$;
  • Related