Thread: C where are oids defined?

C where are oids defined?

From
"frank ernest"
Date:
Hi, I'm new and I can't seem to figure out what values are permitted for OID
PQexecPrepared(parrentcon, insertstmt, 2, argz_str, //fixme);
I've looked in the docs but it's simply evading me. In C the values are of type char * and in the database they are of
typevarchar(255).
 

Thanks



Re: C where are oids defined?

From
Jeff Davis
Date:
On Tue, 2014-07-15 at 17:36 +0200, frank ernest wrote:
> Hi, I'm new and I can't seem to figure out what values are permitted for OID
> PQexecPrepared(parrentcon, insertstmt, 2, argz_str, //fixme);
> I've looked in the docs but it's simply evading me. In C the values are of type char * and in the database they are
oftype varchar(255).
 

It looks like you're talking about PQprepare(), not PQexecPrepared().

You can just use NULL for the paramTypes argument, and normally postgres
will figure out the type and everything will be fine. Specifying the
types might catch certain kinds of mistakes and might save postgres a
small amount of work.

To specify the types, the OID is the internal ID of the postgres type.
For built-in types, this is constant, and most people #include
"catalog/pg_type.h". That allows you to use a name, like VARCHAROID,
INT4OID, etc.

For user-defined types, the OID might be different on different servers,
so it's quite awkward to specify the OID for a user-defined type.

Regards,Jeff Davis





Re: C where are oids defined?

From
"frank ernest"
Date:
> You can just use NULL for the paramTypes argument, and normally postgres
> will figure out the type and everything will be fine. Specifying the
> types might catch certain kinds of mistakes and might save postgres a
> small amount of work.

I like being type safe whenever possible, it's the first thing you [should] learn in C and one less variable when
debugging.

> For user-defined types, the OID might be different on different servers,
> so it's quite awkward to specify the OID for a user-defined type.

The server is going to be run locally so that's not a problem.

Thanks