jolly=>
The fields in pg_group are:
- * groname: the group name. This a char16 and should be purely
+ * groname: the group name. This a name and should be purely
alphanumeric. Do not include underscores or other punctuation.
* grosysid: the group id. This is an int4. This should be unique for
each group.
Type Internal Name Notes
--------------------------------------------------
-CHAR char 1 character }
-CHAR2 char2 2 characters }
-CHAR4 char4 4 characters } optimized for a fixed length
-CHAR8 char8 8 characters }
-CHAR16 char16 16 characters }
+CHAR char 1 character
CHAR(#) bpchar blank padded to the specified fixed length
VARCHAR(#) varchar size specifies maximum length, no padding
TEXT text length limited only by maximum tuple length
</Para>
<Para>
-There are currently other fixed-length character types. These provide no additional
-functionality and are likely to be deprecated in the future.
+There is currently one other fixed-length character type. The <Type>name</Type> type
+only has one purpose and that is to provide <ProductName>Postgres</ProductName> with a
+special type to use for internal names. It is not intended for use by the general user.
+It's length is currently defined as 32 chars but should be reference using NAMEDATALEN.
+This is set at compile time and may change in any future release.
</Para>
<Para>
<TABLE TOCENTRY="1">
-<TITLE><ProductName>Postgres</ProductName> Specialty Character Types</TITLE>
+<TITLE><ProductName>Postgres</ProductName> Specialty Character Type</TITLE>
<TITLEABBREV>Specialty Characters</TITLEABBREV>
<TGROUP COLS="3">
<THEAD>
</THEAD>
<TBODY>
<ROW>
- <ENTRY>char2</ENTRY>
- <ENTRY>2 bytes</ENTRY>
- <ENTRY>Two characters</ENTRY>
- </ROW>
- <ROW>
- <ENTRY>char4</ENTRY>
- <ENTRY>4 bytes</ENTRY>
- <ENTRY>Four characters</ENTRY>
- </ROW>
- <ROW>
- <ENTRY>char8</ENTRY>
- <ENTRY>8 bytes</ENTRY>
- <ENTRY>Eight characters</ENTRY>
- </ROW>
- <ROW>
- <ENTRY>char16</ENTRY>
- <ENTRY>16 bytes</ENTRY>
- <ENTRY>Sixteen characters</ENTRY>
+ <ENTRY>name</ENTRY>
+ <ENTRY>32 bytes</ENTRY>
+ <ENTRY>Thirty-two character internal type</ENTRY>
</ROW>
</TBODY>
</TGROUP>
AS 'SELECT \'None\'::text AS name,
1000 AS salary,
25 AS age,
- \'none\'::char16 AS dept;'
+ \'none\'::text AS dept;'
LANGUAGE 'sql';
</ProgramListing>
<Para>
On the other hand, fixed-length types of any size may
be passed by-reference. For example, here is a sample
- implementation of the <ProductName>Postgres</ProductName> char16 type:
+ implementation of a <ProductName>Postgres</ProductName> type:
<ProgramListing>
/* 16-byte structure, passed by reference */
structure, we might use a code fragment like this:
<ProgramListing>
#include "postgres.h"
- #include "utils/palloc.h"
...
char buffer[40]; /* our source data */
...
Suppose <FileName>funcs.c</FileName> look like:
<ProgramListing>
#include <string.h>
- #include "postgres.h" /* for char16, etc. */
- #include "utils/palloc.h" /* for palloc */
+ #include "postgres.h"
int
add_one(int arg)
{
return(arg + 1);
}
- char16 *
- concat16(char16 *arg1, char16 *arg2)
+ text *
+ concat_text(text *arg1, text *arg2)
{
- char16 *new_c16 = (char16 *) palloc(sizeof(char16));
- memset((void *) new_c16, 0, sizeof(char16));
- (void) strncpy(new_c16, arg1, 16);
- return (char16 *)(strncat(new_c16, arg2, 16));
+ int32 new_text_size = VARSIZE(arg1) + VARSIZE(arg2) - VARHDRSZ;
+ text *new_text = (text *) palloc(new_text_size);
+
+ memset((void *) new_text, 0, new_text_size);
+ VARSIZE(new_text) = new_text_size;
+ strncpy(VARDATA(new_text), VARDATA(arg1), VARSIZE(arg1)-VARHDRSZ);
+ strncat(VARDATA(new_text), VARDATA(arg2), VARSIZE(arg2)-VARHDRSZ);
+ return (new_text);
}
text *
copytext(text *t)
CREATE FUNCTION add_one(int4) RETURNS int4
AS 'PGROOT/tutorial/obj/funcs.so' LANGUAGE 'c';
- CREATE FUNCTION concat16(char16, char16) RETURNS char16
+ CREATE FUNCTION concat_text(text, text) RETURNS text
AS 'PGROOT/tutorial/obj/funcs.so' LANGUAGE 'c';
CREATE FUNCTION copytext(text) RETURNS text
In the query above, we can define c_overpaid as:
<ProgramListing>
- #include "postgres.h" /* for char16, etc. */
+ #include "postgres.h"
#include "libpq-fe.h" /* for TUPLE */
bool
c_overpaid(TUPLE t,/* the current instance of EMP */
is null. <Acronym>GetAttributeByName</Acronym> will align data properly
so you can cast its return value to the desired type.
For example, if you have an attribute name which is of
- the type char16, the <Acronym>GetAttributeByName</Acronym> call would look
+ the type name, the <Acronym>GetAttributeByName</Acronym> call would look
like:
<ProgramListing>
char *str;
</Para>
<ListItem>
<Para> Most of the internal <ProductName>Postgres</ProductName> types are declared
- in postgres.h, so it's usually a good idea to
- include that file as well.
+ in postgres.h, so it's a good idea to always
+ include that file as well. Including postgres.h
+ will also include elog.h and palloc.h for you.
</Para>
<ListItem>
<Para> Compiling and loading your object code so that