Getting Constrint information..??

Started by Steffen Nielsenalmost 24 years ago2 messageshackers
Jump to latest
#1Steffen Nielsen
styf@cs.auc.dk

Help!

Can anyone tell me what wrong with the following codesnippet. I nuke the
server when called (stored procedure)

... some VALID spi_exec call :-) has been done ...

TupleDesc tupdesc = SPI_tuptable->tupdesc;
TupleConstr *tupconstr = SPI_tuptable->tupdesc->constr;
ConstrCheck *check = tupconstr->check;
SPITupleTable *tuptable = SPI_tuptable;
char *ccbin;

char buf[8192];
int i;

for (i = 1, buf[0] = 0; i <= tupdesc->natts; i++) {
ccbin = check[i].ccbin;
sprintf(buf + strlen (buf), "%s, %s",
SPI_fname(tupdesc,i),
ccbin);
elog (NOTICE, "%s", buf);
}

I have not had any luck :-( I'm a C beginner thou, so maybe i screw up when
accessing the structures

Any help is appreciated

/Steffen Nielsen

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Steffen Nielsen (#1)
Re: Getting Constrint information..??

Steffen Nielsen <styf@cs.auc.dk> writes:

Can anyone tell me what wrong with the following codesnippet. I nuke the
server when called (stored procedure)

for (i = 1, buf[0] = 0; i <= tupdesc->natts; i++) {
ccbin = check[i].ccbin;

Well, for one thing, the number of check[] array entries is probably not
equal to the number of attributes of the relation. tupconstr->num_check
tells you how many there are. For another, check[] should be indexed
from 0 not 1 (just like all C arrays).

regards, tom lane