Postgres QUERY ROW NEED HELP

Hi Guys

I am facing a weird issue with postgres usage in Golang. This is what I am doing. I need to get the UID after inserting a new user. Instead when I log the uid after scanning I see a time stamp along with the uid.

    var uid int
    err := database.Handle.QueryRow("INSERT INTO users (username, isactive) values ($1,TRUE) RETURNING uid", username).Scan(&uid)
log(uid)

RESULT –
2018/02/24 06:12:17 sandyk

Need help guys to understand how this is happening. My DB create statement is as follows :-
Create table users ( uid serial not null,
username character varying(200) not null,
isactive boolean not null,
created timestamp default now());

Hi Sandeep,

Could you please post a more complete code snippet?

If you serialize into an int there is just no way you can get a string out of it :slight_smile:

Hi @Giulio_Iotti

Thanks for responding. I mean I did use uid of type int right?
I ended up fixing it by changing table create statment into –

Create table users ( uid serial not null,
username character varying(200) not null,
isactive boolean not null,
created timestamp default now())
WITH(OIDS=FALSE);

Not sure how that changed anything

Are you meaning *uuid? Because that will not be serializable nor an integer

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.