vendredi 31 janvier 2020

Set columns values to NULL at run time using postgres API for C++(pqxx)

I am using C++11 and Postgres(10.4). I have a scenario where I'm creating a dynamic query using pqxx library which will be executed at run time.

The issue is that the dynamic query(an insert statement) i'm creating is having approxmiately 160 columns. I want to set some columns values to 'NULL' based on the input data. These columns are not fixed, for e.g.
"INSERT INTO players VALUES ($1, $2)";

In the above query at run time either of $1 or $2 or both can have null values.

Now with the prepared function of worker class, I'm not sure how to set column name to NULL. For e.g. "prepared("testfunction")(name)(score).exec();" In the above example either of name or score can be "NULL" based on input data.

NOTE :- I know how to set NULL value for a particular column statically as below : "prepared("testfunction")(name)().exec();" As done above, if I know that score is to be NULL, I can do it like above. But, in my issue any column can have null value.

Please advice how this can be achieved.

Thanks!

Aucun commentaire:

Enregistrer un commentaire