From: Bruce Momjian Date: Sun, 26 Apr 1998 04:18:06 +0000 (+0000) Subject: Doc updates from Darren on char2-16 removal X-Git-Tag: REL6_4_2~1068 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d31736e92bb270b2324ae6c97c42d500ff555705;p=postgresql Doc updates from Darren on char2-16 removal --- diff --git a/doc/FAQ b/doc/FAQ index c0728c25c7..59ee0191e8 100644 --- a/doc/FAQ +++ b/doc/FAQ @@ -543,7 +543,7 @@ Section 3: PostgreSQL Features 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. @@ -622,11 +622,7 @@ Section 3: PostgreSQL Features 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 diff --git a/doc/src/sgml/advanced.sgml b/doc/src/sgml/advanced.sgml index 9d8b2082b8..c9d2256b19 100644 --- a/doc/src/sgml/advanced.sgml +++ b/doc/src/sgml/advanced.sgml @@ -126,7 +126,7 @@ SELECT c.name, c.altitude CREATE TABLE SAL_EMP ( name text, pay_by_quarter int4[], - schedule char16[][] + schedule text[][] ); @@ -135,7 +135,7 @@ CREATE TABLE SAL_EMP ( The above query will create a class named SAL_EMP with a text string (name), a one-dimensional array of int4 (pay_by_quarter), which represents the employee's - salary by quarter and a two-dimensional array of char16 + salary by quarter and a two-dimensional array of text (schedule), which represents the employee's weekly schedule. Now we do some INSERTSs; note that when appending to an array, we enclose the values within diff --git a/doc/src/sgml/array.sgml b/doc/src/sgml/array.sgml index 4b73608600..aada6f71c6 100644 --- a/doc/src/sgml/array.sgml +++ b/doc/src/sgml/array.sgml @@ -20,7 +20,7 @@ This must become a chapter on array behavior. Volunteers? - thomas 1998-01-12 CREATE TABLE SAL_EMP ( name text, pay_by_quarter int4[], - schedule char16[][] + schedule text[][] ); @@ -29,7 +29,7 @@ CREATE TABLE SAL_EMP ( The above query will create a class named SAL_EMP with a text string (name), a one-dimensional array of int4 (pay_by_quarter), which represents the employee's - salary by quarter and a two-dimensional array of char16 + salary by quarter and a two-dimensional array of text (schedule), which represents the employee's weekly schedule. Now we do some INSERTSs; note that when appending to an array, we enclose the values within diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml index 48c2a49070..70a0d383c0 100644 --- a/doc/src/sgml/datatype.sgml +++ b/doc/src/sgml/datatype.sgml @@ -368,13 +368,16 @@ limit to be declared on the size of the field. -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 name type +only has one purpose and that is to provide Postgres 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. -<ProductName>Postgres</ProductName> Specialty Character Types +<ProductName>Postgres</ProductName> Specialty Character TypeSpecialty Characters @@ -386,24 +389,9 @@ functionality and are likely to be deprecated in the future. - char2 - 2 bytes - Two characters - - - char4 - 4 bytes - Four characters - - - char8 - 8 bytes - Eight characters - - - char16 - 16 bytes - Sixteen characters + name + 32 bytes + Thirty-two character internal type diff --git a/doc/src/sgml/libpq.sgml b/doc/src/sgml/libpq.sgml index 127f24517d..9560818794 100644 --- a/doc/src/sgml/libpq.sgml +++ b/doc/src/sgml/libpq.sgml @@ -736,7 +736,7 @@ void PQputline(PGconn *conn, int PQendcopy(PGconn *conn); -PQexec(conn, "create table foo (a int4, b char16, d float8)"); +PQexec(conn, "create table foo (a int4, b text, d float8)"); PQexec(conn, "copy foo from stdin"); PQputline(conn, "3<TAB>hello world<TAB>4.5\n"); PQputline(conn,"4<TAB>goodbye world<TAB>7.11\n"); diff --git a/doc/src/sgml/xfunc.sgml b/doc/src/sgml/xfunc.sgml index f1275bbb46..880ea9fdc4 100644 --- a/doc/src/sgml/xfunc.sgml +++ b/doc/src/sgml/xfunc.sgml @@ -136,7 +136,7 @@ AS 'SELECT \'None\'::text AS name, 1000 AS salary, 25 AS age, - \'none\'::char16 AS dept;' + \'none\'::text AS dept;' LANGUAGE 'sql'; @@ -263,7 +263,7 @@ The reason why, in general, we must use the function On the other hand, fixed-length types of any size may be passed by-reference. For example, here is a sample - implementation of the Postgres char16 type: + implementation of a Postgres type: /* 16-byte structure, passed by reference */ @@ -305,7 +305,6 @@ The reason why, in general, we must use the function structure, we might use a code fragment like this: #include "postgres.h" - #include "utils/palloc.h" ... char buffer[40]; /* our source data */ ... @@ -322,20 +321,23 @@ The reason why, in general, we must use the function Suppose funcs.c look like: #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) @@ -364,7 +366,7 @@ The reason why, in general, we must use the function 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 @@ -401,7 +403,7 @@ The reason why, in general, we must use the function In the query above, we can define c_overpaid as: - #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 */ @@ -426,7 +428,7 @@ The reason why, in general, we must use the function is null. GetAttributeByName 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 GetAttributeByName call would look + the type name, the GetAttributeByName call would look like: char *str; @@ -517,8 +519,9 @@ Most of the header (include) files for Postgres Most of the internal Postgres 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. Compiling and loading your object code so that