PostgreSQL C String to CHARACTER internal representation -


I am trying to convert a C string to an internal representation of the character of PostgreSQL. I am using the varchar.c function in the bpcharin function. There are two arguments for this function: C string datum and atttypmod . It has been mentioned that the atttypmod type plus is the declared length of VARHDRSZ.

My conversion function is:

  result = directfunction call 2 (bpcirin, csrringGetDatum (str), VARHDRSZ +?);   

My string str value will be one of the columns datatype of my table. Therefore, I need the declared column data type length. This information is stored in the character_maximum_length in the information_schema.column view.

My question is, how do I get character_maximum_length ? In C code?

Thank you.

Unless you are using the char data type You need bpchar CodeTringGetDatum (for typed values ​​for cstring ) or typed CStringGetTextDatum ( text ) Enough values) is enough.


It looks like you're using char (n) , that is, bpchar . Frankly, the best thing to do is not to do this ; This is a quirky type that should be replaced with a plain text or varchar in almost all cases.

If you should use it ... well, take a look at us at pg_cast :

  regress = & gt; C. *, From Tfrom.typname, f.proname pg_cast to c cctctunf = c on cg.procame, c on cachesource c txtom c.castource = tfrom.oid internally included pg_type tto c.casttarget = tto.oid left on the outer included pg_proc F. .oid where tto.typname = 'bpchar'; Hairdresser | Racial targets Castfunk | Castanetext | Consumption | Typname | | Proname ------------ + ------------ + ---------- + ------------ - + ------------ + --------- + --------- 25 | 1042 | 0 | I B Text | 1043 | 1042 | 0 | I B Varchar | | 18 | 1042 | 860 | One | F | Four Bept 19 1042 | 408 | One | F | Name | Bipcher 650 | 1042 | 730 | One | F | Cedar | Lesson 869 | 1042 | 730 | One | F | Inet | | Text16 | 1042 | 2971 | One | F | Bull | Lesson 142 | 1042 | 0 | One | B Xml | 1042 | 1042 | 668 | I F | Bipcher | Bipcher (9 lines)   

castmethod = 'b' entries are for text and varchar . According to the manual, b means:

types are binary-copper, thus no conversion is required

.. So you can use CStringGetTextDatum to create bpchar . However, no length will be examined.

If you want to check the type, you will need to call the bpchar function, which is called on four to four points. It will check / cut the length, it takes three arguments - the text, the maximum length and whether it is an inherent or clear cast.

For example (Untested):

  DirectFunction Call 3 (CSTIrGDATTitem (IISGSR), int 32 GETDATAM (MAX_LAN), BULGATEDATAM (false));   

The last rule controls the rules of deduction; See the comment on bpchar for details on src / backend / utils / adt / varchar.c .

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -