Casting a primary key as a VARCHAR/STRING

hello -

in trying to work around the SERIAL PRIMARY KEY and jScript conflict, i started wondering if CAST might work:

SELECT COUNT(*) FROM sequelizeTable  WHERE CAST('sequelizeId' AS STRING)='235801104191094785';
//returns zero for some unknown reason

SELECT COUNT(*) FROM sequelizeTable   WHERE  sequelizeId  = 235801104191094785;
//returns one as expected

and of course i tried CAST VARCHAR too. does anybody have any idea why i cannot seem to cast the key as as a non-integer?

also, what is the daily newbie idiot question limit? or is it a weekly limit?

The problem with your first idea is that you’re casting the string literal 'sequelizeId' to a string and comparing that. That’s why it returns 0 every time - the WHERE condition is always false.

Try the following instead (you can use the ::string shortcut to make your query a little easier to read as well):

SELECT COUNT(*) FROM sequelizeTable WHERE sequelizeId::string ='235801104191094785';

perfect, thank you. now to figure out how to get sequelize to recognize this.

all of my SERIAL integer values are being casted as strings over the network. and jScript wont let me cast them back as integers, since the SERIAL size is 18 and jScript integer limit is 17 digits.

UPDATE: maybe we cannot cast the column name as a string, but we can indeed cast the comparison string as an integer - which is probably much better anyways.