1

how can I get an arg varchar from PG_FUNCTION_ARGS?

I whant to contruct this query but nor with PG_GETARG_VARCHAR_P neither with PG_GETARG_TEXT_P works.

  sprintf(query,"SELECT abp1::real, abp2::real "
                "FROM imu.calcolo WHERE cf = %s;", PG_GETARG_VARCHAR_P(0));

I get the WARNING compiling

warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘struct VarChar *’ [-Wformat]

and after a strange content for the PG_GETARG_VARCHAR_P(0), it is 'P' ??

can someone give an hint?

1 Answer 1

1

Use VARDATA:

VARDATA(PG_GETARG_VARCHAR_P(0))

EDIT

Remember to also use VARSIZE to get the length of data since as far as I know, data is not null-terminated and sprintf would blow up the destination buffer.

Further information here: http://www.postgresql.org/docs/8.3/static/xfunc-c.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.