+ linkend="PGTYPEStimestampfmtasc">. See the documentation there in
+ order to find out about the possible formatting mask entries.
int PGTYPEStimestamp_add_interval(timestamp *tin, interval *span, timestamp *tout);
- The function receives a pointer to a timestamp variable tin>
- and a pointer to an interval variable span>. It adds the
- interval to the timestamp and saves the resulting timestamp in the
- variable that tout> points to.
+ The function receives a pointer to a timestamp variable tin>
+ and a pointer to an interval variable span>. It adds the
+ interval to the timestamp and saves the resulting timestamp in the
+ variable that tout> points to.
- Upon success, the function returns 0 and a negative value if an
- error occurred.
+ Upon success, the function returns 0 and a negative value if an
+ error occurred.
int PGTYPEStimestamp_sub_interval(timestamp *tin, interval *span, timestamp *tout);
- The function subtracts the interval variable that span>
- points to from the timestamp variable that tin> points to
- and saves the result into the variable that tout> points
- to.
+ The function subtracts the interval variable that span>
+ points to from the timestamp variable that tin> points to
+ and saves the result into the variable that tout> points
+ to.
- Upon success, the function returns 0 and a negative value if an
- error occurred.
+ Upon success, the function returns 0 and a negative value if an
+ error occurred.
interval *PGTYPESinterval_from_asc(char *str, char **endptr);
- The function parses the input string str> and returns a
- pointer to an allocated interval variable.
- At the moment ecpg always parses
- the complete string and so it currently does not support to store the
- address of the first invalid character in *endptr.
- You can safely set endptr to NULL.
+ The function parses the input string str> and returns a
+ pointer to an allocated interval variable.
+ At the moment ecpg always parses
+ the complete string and so it currently does not support to store the
+ address of the first invalid character in *endptr.
+ You can safely set endptr to NULL.
char *PGTYPESinterval_to_asc(interval *span);
- The function converts the interval variable that span>
- points to into a C char*. The output looks like this example:
- @ 1 day 12 hours 59 mins 10 secs.
+ The function converts the interval variable that span>
+ points to into a C char*. The output looks like this example:
+ @ 1 day 12 hours 59 mins 10 secs.
int PGTYPESinterval_copy(interval *intvlsrc, interval *intvldest);
- The function copies the interval variable that intvlsrc>
- points to into the variable that intvldest> points to. Note
- that you need to allocate the memory for the destination variable
- before.
+ The function copies the interval variable that intvlsrc>
+ points to into the variable that intvldest> points to. Note
+ that you need to allocate the memory for the destination variable
+ before.
PGTYPES_NUM_BAD_NUMERIC
- An argument should contain a numeric variable (or point to a numeric
- variable) but in fact its in-memory representation was invalid.
+ An argument should contain a numeric variable (or point to a numeric
+ variable) but in fact its in-memory representation was invalid.
PGTYPES_NUM_OVERFLOW
- An overflow occurred. Since the numeric type can deal with almost
- arbitrary precision, converting a numeric variable into other types
- might cause overflow.
+ An overflow occurred. Since the numeric type can deal with almost
+ arbitrary precision, converting a numeric variable into other types
+ might cause overflow.
PGTYPES_NUM_OVERFLOW
- An underflow occurred. Since the numeric type can deal with almost
- arbitrary precision, converting a numeric variable into other types
- might cause underflow.
+ An underflow occurred. Since the numeric type can deal with almost
+ arbitrary precision, converting a numeric variable into other types
+ might cause underflow.
PGTYPESInvalidTimestamp
- A value of type timestamp representing an invalid time stamp. This is
- returned by the function PGTYPEStimestamp_from_asc> on
- parse error.
- Note that due to the internal representation of the timestamp datatype,
- PGTYPESInvalidTimestamp is also a valid timestamp at
- the same time. It is set to 1899-12-31 23:59:59>. In order
- to detect errors, make sure that your application does not only test
- for PGTYPESInvalidTimestamp but also for
- errno != 0> after each call to
- PGTYPEStimestamp_from_asc>.
+ A value of type timestamp representing an invalid time stamp. This is
+ returned by the function PGTYPEStimestamp_from_asc> on
+ parse error.
+ Note that due to the internal representation of the timestamp datatype,
+ PGTYPESInvalidTimestamp is also a valid timestamp at
+ the same time. It is set to 1899-12-31 23:59:59>. In order
+ to detect errors, make sure that your application does not only test
+ for PGTYPESInvalidTimestamp but also for
+ errno != 0> after each call to
+ PGTYPEStimestamp_from_asc>.
CLOSE DATABASE>
- This statement closes the current connection. In fact, this is a
- synonym for ecpg's DISCONNECT CURRENT>.:
+ This statement closes the current connection. In fact, this is a
+ synonym for ecpg's DISCONNECT CURRENT>.:
$CLOSE DATABASE; /* close the current connection */
EXEC SQL CLOSE DATABASE;
int decadd(decimal *arg1, decimal *arg2, decimal *sum);
- The function receives a pointer to the first operand of type decimal
- (arg1>), a pointer to the second operand of type decimal
- (arg2>) and a pointer to a value of type decimal that will
- contain the sum (sum>). On success, the function returns 0.
- ECPG_INFORMIX_NUM_OVERFLOW is returned in case of overflow and
- ECPG_INFORMIX_NUM_UNDERFLOW in case of underflow. -1 is returned for
- other failures and errno is set to the respective errno number of the
- pgtypeslib.
+ The function receives a pointer to the first operand of type decimal
+ (arg1>), a pointer to the second operand of type decimal
+ (arg2>) and a pointer to a value of type decimal that will
+ contain the sum (sum>). On success, the function returns 0.
+ ECPG_INFORMIX_NUM_OVERFLOW is returned in case of overflow and
+ ECPG_INFORMIX_NUM_UNDERFLOW in case of underflow. -1 is returned for
+ other failures and errno is set to the respective errno number of the
+ pgtypeslib.
int deccmp(decimal *arg1, decimal *arg2);
- The function receives a pointer to the first decimal value
- (arg1>), a pointer to the second decimal value
- (arg2>) and returns an integer value that indicates which is
- the bigger value.
+ The function receives a pointer to the first decimal value
+ (arg1>), a pointer to the second decimal value
+ (arg2>) and returns an integer value that indicates which is
+ the bigger value.
- 1, if the value that arg1> points to is bigger than the
- value that var2> points to
+ 1, if the value that arg1> points to is bigger than the
+ value that var2> points to
- -1, if the value that arg1> points to is smaller than the
- value that arg2> points to
+ -1, if the value that arg1> points to is smaller than the
+ value that arg2> points to
- 0, if the value that arg1> points to and the value that
- arg2> points to are equal
+ 0, if the value that arg1> points to and the value that
+ arg2> points to are equal
void deccopy(decimal *src, decimal *target);
- The function receives a pointer to the decimal value that should be
- copied as the first argument (src>) and a pointer to the
- target structure of type decimal (target>) as the second
- argument.
+ The function receives a pointer to the decimal value that should be
+ copied as the first argument (src>) and a pointer to the
+ target structure of type decimal (target>) as the second
+ argument.
int deccvasc(char *cp, int len, decimal *np);
- The function receives a pointer to string that contains the string
- representation of the number to be converted (cp>) as well
- as its length len>. np> is a pointer to the
- decimal value that saves the result of the operation.
+ The function receives a pointer to string that contains the string
+ representation of the number to be converted (cp>) as well
+ as its length len>. np> is a pointer to the
+ decimal value that saves the result of the operation.
Valid formats are for example:
-32.84e-4.
- The function returns 0 on success. If overflow or underflow occurred,
- ECPG_INFORMIX_NUM_OVERFLOW> or
- ECPG_INFORMIX_NUM_UNDERFLOW> is returned. If the ASCII
- representation could not be parsed,
- ECPG_INFORMIX_BAD_NUMERIC> is returned or
- ECPG_INFORMIX_BAD_EXPONENT> if this problem occurred while
- parsing the exponent.
+ The function returns 0 on success. If overflow or underflow occurred,
+ ECPG_INFORMIX_NUM_OVERFLOW> or
+ ECPG_INFORMIX_NUM_UNDERFLOW> is returned. If the ASCII
+ representation could not be parsed,
+ ECPG_INFORMIX_BAD_NUMERIC> is returned or
+ ECPG_INFORMIX_BAD_EXPONENT> if this problem occurred while
+ parsing the exponent.
int deccvdbl(double dbl, decimal *np);
- The function receives the variable of type double that should be
- converted as its first argument (dbl>). As the second
- argument (np>), the function receives a pointer to the
- decimal variable that should hold the result of the operation.
+ The function receives the variable of type double that should be
+ converted as its first argument (dbl>). As the second
+ argument (np>), the function receives a pointer to the
+ decimal variable that should hold the result of the operation.
- The function returns 0 on success and a negative value if the
- conversion failed.
+ The function returns 0 on success and a negative value if the
+ conversion failed.
int deccvint(int in, decimal *np);
- The function receives the variable of type int that should be
- converted as its first argument (in>). As the second
- argument (np>), the function receives a pointer to the
- decimal variable that should hold the result of the operation.
+ The function receives the variable of type int that should be
+ converted as its first argument (in>). As the second
+ argument (np>), the function receives a pointer to the
+ decimal variable that should hold the result of the operation.
- The function returns 0 on success and a negative value if the
- conversion failed.
+ The function returns 0 on success and a negative value if the
+ conversion failed.
int deccvlong(long lng, decimal *np);
- The function receives the variable of type long that should be
- converted as its first argument (lng>). As the second
- argument (np>), the function receives a pointer to the
- decimal variable that should hold the result of the operation.
+ The function receives the variable of type long that should be
+ converted as its first argument (lng>). As the second
+ argument (np>), the function receives a pointer to the
+ decimal variable that should hold the result of the operation.
- The function returns 0 on success and a negative value if the
- conversion failed.
+ The function returns 0 on success and a negative value if the
+ conversion failed.
int decdiv(decimal *n1, decimal *n2, decimal *result);
- The function receives pointers to the variables that are the first
- (n1>) and the second (n2>) operands and
- calculates n1>/n2>. result> is a
- pointer to the variable that should hold the result of the operation.
+ The function receives pointers to the variables that are the first
+ (n1>) and the second (n2>) operands and
+ calculates n1>/n2>. result> is a
+ pointer to the variable that should hold the result of the operation.
- On success, 0 is returned and a negative value if the division fails.
- If overflow or underflow occurred, the function returns
- ECPG_INFORMIX_NUM_OVERFLOW> or
- ECPG_INFORMIX_NUM_UNDERFLOW> respectively. If an attempt to
- divide by zero is observed, the function returns
- ECPG_INFORMIX_DIVIDE_ZERO.
+ On success, 0 is returned and a negative value if the division fails.
+ If overflow or underflow occurred, the function returns
+ ECPG_INFORMIX_NUM_OVERFLOW> or
+ ECPG_INFORMIX_NUM_UNDERFLOW> respectively. If an attempt to
+ divide by zero is observed, the function returns
+ ECPG_INFORMIX_DIVIDE_ZERO.
int decmul(decimal *n1, decimal *n2, decimal *result);
- The function receives pointers to the variables that are the first
- (n1>) and the second (n2>) operands and
- calculates n1>*n2>. result> is a
- pointer to the variable that should hold the result of the operation.
+ The function receives pointers to the variables that are the first
+ (n1>) and the second (n2>) operands and
+ calculates n1>*n2>. result> is a
+ pointer to the variable that should hold the result of the operation.
- On success, 0 is returned and a negative value if the multiplication
- fails. If overflow or underflow occurred, the function returns
- ECPG_INFORMIX_NUM_OVERFLOW> or
- ECPG_INFORMIX_NUM_UNDERFLOW> respectively.
+ On success, 0 is returned and a negative value if the multiplication
+ fails. If overflow or underflow occurred, the function returns
+ ECPG_INFORMIX_NUM_OVERFLOW> or
+ ECPG_INFORMIX_NUM_UNDERFLOW> respectively.
int decsub(decimal *n1, decimal *n2, decimal *result);
- The function receives pointers to the variables that are the first
- (n1>) and the second (n2>) operands and
- calculates n1>-n2>. result> is a
- pointer to the variable that should hold the result of the operation.
+ The function receives pointers to the variables that are the first
+ (n1>) and the second (n2>) operands and
+ calculates n1>-n2>. result> is a
+ pointer to the variable that should hold the result of the operation.
- On success, 0 is returned and a negative value if the subtraction
- fails. If overflow or underflow occurred, the function returns
- ECPG_INFORMIX_NUM_OVERFLOW> or
- ECPG_INFORMIX_NUM_UNDERFLOW> respectively.
+ On success, 0 is returned and a negative value if the subtraction
+ fails. If overflow or underflow occurred, the function returns
+ ECPG_INFORMIX_NUM_OVERFLOW> or
+ ECPG_INFORMIX_NUM_UNDERFLOW> respectively.
dectoasc>
- Convert a variable of type decimal to its ASCII representation in a C
- char* string.
+ Convert a variable of type decimal to its ASCII representation in a C
+ char* string.
int dectoasc(decimal *np, char *cp, int len, int right)
- The function receives a pointer to a variable of type decimal
- (np>) that it converts to its textual representation.
- cp> is the buffer that should hold the result of the
- operation. The parameter right> specifies, how many digits
- right of the decimal point should be included in the output. The result
- will be rounded to this number of decimal digits. Setting
- right> to -1 indicates that all available decimal digits
- should be included in the output. If the length of the output buffer,
- which is indicated by len> is not sufficient to hold the
- textual representation including the trailing NUL character, only a
- single *> character is stored in the result and -1 is
- returned.
-
- The function returns either -1 if the buffer cp> was too
- small or ECPG_INFORMIX_OUT_OF_MEMORY> if memory was
- exhausted.
+ The function receives a pointer to a variable of type decimal
+ (np>) that it converts to its textual representation.
+ cp> is the buffer that should hold the result of the
+ operation. The parameter right> specifies, how many digits
+ right of the decimal point should be included in the output. The result
+ will be rounded to this number of decimal digits. Setting
+ right> to -1 indicates that all available decimal digits
+ should be included in the output. If the length of the output buffer,
+ which is indicated by len> is not sufficient to hold the
+ textual representation including the trailing NUL character, only a
+ single *> character is stored in the result and -1 is
+ returned.
+
+ The function returns either -1 if the buffer cp> was too
+ small or ECPG_INFORMIX_OUT_OF_MEMORY> if memory was
+ exhausted.
int dectodbl(decimal *np, double *dblp);
- The function receives a pointer to the decimal value to convert
- (np>) and a pointer to the double variable that
- should hold the result of the operation (dblp>).
+ The function receives a pointer to the decimal value to convert
+ (np>) and a pointer to the double variable that
+ should hold the result of the operation (dblp>).
- On success, 0 is returned and a negative value if the conversion
- failed.
+ On success, 0 is returned and a negative value if the conversion
+ failed.
int dectoint(decimal *np, int *ip);
- The function receives a pointer to the decimal value to convert
- (np>) and a pointer to the integer variable that
- should hold the result of the operation (ip>).
+ The function receives a pointer to the decimal value to convert
+ (np>) and a pointer to the integer variable that
+ should hold the result of the operation (ip>).
- On success, 0 is returned and a negative value if the conversion
- failed. If an overflow occurred, ECPG_INFORMIX_NUM_OVERFLOW>
- is returned.
+ On success, 0 is returned and a negative value if the conversion
+ failed. If an overflow occurred, ECPG_INFORMIX_NUM_OVERFLOW>
+ is returned.
- Note that the ecpg implementation differs from the
Informix
- implementation.
Informix limits an integer to the range from -32767 to
- 32767, while the limits in the ecpg implementation depend on the
- architecture (-INT_MAX .. INT_MAX>).
+
Note that the ecpg implementation differs from the
Informix
+
implementation.
Informix limits an integer to the range from -32767 to
+ 32767, while the limits in the ecpg implementation depend on the
+ architecture (-INT_MAX .. INT_MAX>).
int dectolong(decimal *np, long *lngp);
- The function receives a pointer to the decimal value to convert
- (np>) and a pointer to the long variable that
- should hold the result of the operation (lngp>).
+ The function receives a pointer to the decimal value to convert
+ (np>) and a pointer to the long variable that
+ should hold the result of the operation (lngp>).
- On success, 0 is returned and a negative value if the conversion
- failed. If an overflow occurred, ECPG_INFORMIX_NUM_OVERFLOW>
- is returned.
+ On success, 0 is returned and a negative value if the conversion
+ failed. If an overflow occurred, ECPG_INFORMIX_NUM_OVERFLOW>
+ is returned.
- Note that the ecpg implementation differs from the
Informix
- implementation.
Informix limits a long integer to the range from
- -2,147,483,647 to 2,147,483,647, while the limits in the ecpg
- implementation depend on the architecture (-LONG_MAX ..
- LONG_MAX>).
+
Note that the ecpg implementation differs from the
Informix
+
implementation.
Informix limits a long integer to the range from
+ -2,147,483,647 to 2,147,483,647, while the limits in the ecpg
+ implementation depend on the architecture (-LONG_MAX ..
+ LONG_MAX>).
int rdatestr(date d, char *str);
- The function receives two arguments, the first one is the date to
- convert (d> and the second one is a pointer to the target
- string. The output format is always yyyy-mm-dd>, so you need
- to allocate at least 11 bytes (including the NUL-terminator) for the
- string.
+ The function receives two arguments, the first one is the date to
+ convert (d> and the second one is a pointer to the target
+ string. The output format is always yyyy-mm-dd>, so you need
+ to allocate at least 11 bytes (including the NUL-terminator) for the
+ string.
- The function returns 0 on success and a negative value in case of
- error.
+ The function returns 0 on success and a negative value in case of
+ error.
- Note that ecpg's implementation differs from the
Informix
- implementation. In
Informix the format can be influenced by setting
- environment variables. In ecpg however, you cannot change the output
- format.
+
Note that ecpg's implementation differs from the
Informix
+
implementation. In
Informix the format can be influenced by setting
+ environment variables. In ecpg however, you cannot change the output
+ format.
int rstrdate(char *str, date *d);
- The function receives the textual representation of the date to convert
- (str>) and a pointer to a variable of type date
- (d>). This function does not allow you to specify a format
- mask. It uses the default format mask of
Informix which is
- mm/dd/yyyy>. Internally, this function is implemented by
- means of rdefmtdate>. Therefore, rstrdate> is
- not faster and if you have the choice you should opt for
- rdefmtdate> which allows you to specify the format mask
- explicitly.
+ The function receives the textual representation of the date to convert
+ (str>) and a pointer to a variable of type date
+ (d>). This function does not allow you to specify a format
+
mask. It uses the default format mask of
Informix which is
+ mm/dd/yyyy>. Internally, this function is implemented by
+ means of rdefmtdate>. Therefore, rstrdate> is
+ not faster and if you have the choice you should opt for
+ rdefmtdate> which allows you to specify the format mask
+ explicitly.
The function returns the same values as rdefmtdate>.
void rtoday(date *d);
- The function receives a pointer to a date variable (d>)
- that it sets to the current date.
+ The function receives a pointer to a date variable (d>)
+ that it sets to the current date.
- Internally this function uses the
- function.
+ Internally this function uses the
+ function.
rjulmdy>
- Extract the values for the day, the month and the year from a variable
- of type date.
+ Extract the values for the day, the month and the year from a variable
+ of type date.
int rjulmdy(date d, short mdy[3]);
- The function receives the date d> and a pointer to an array
- of 3 short integer values mdy>. The variable name indicates
- the sequential order: mdy[0]> will be set to contain the
- number of the month, mdy[1]> will be set to the value of the
- day and mdy[2]> will contain the year.
+ The function receives the date d> and a pointer to an array
+ of 3 short integer values mdy>. The variable name indicates
+ the sequential order: mdy[0]> will be set to contain the
+ number of the month, mdy[1]> will be set to the value of the
+ day and mdy[2]> will contain the year.
The function always returns 0 at the moment.
- Internally the function uses the
- function.
+ Internally the function uses the
+ function.
rdefmtdate>
- Use a format mask to convert a character string to a value of type
- date.
+ Use a format mask to convert a character string to a value of type
+ date.
int rdefmtdate(date *d, char *fmt, char *str);
- The function receives a pointer to the date value that should hold the
- result of the operation (d>), the format mask to use for
- parsing the date (fmt>) and the C char* string containing
- the textual representation of the date (str>). The textual
- representation is expected to match the format mask. However you do not
- need to have a 1:1 mapping of the string to the format mask. The
- function only analyzes the sequential order and looks for the literals
- yy or yyyy that indicate the
- position of the year, mm to indicate the position of
- the month and dd to indicate the position of the
- day.
+ The function receives a pointer to the date value that should hold the
+ result of the operation (d>), the format mask to use for
+ parsing the date (fmt>) and the C char* string containing
+ the textual representation of the date (str>). The textual
+ representation is expected to match the format mask. However you do not
+ need to have a 1:1 mapping of the string to the format mask. The
+ function only analyzes the sequential order and looks for the literals
+ yy or yyyy that indicate the
+ position of the year, mm to indicate the position of
+ the month and dd to indicate the position of the
+ day.
The function returns the following values:
- ECPG_INFORMIX_ENOSHORTDATE> - The date does not contain
- delimiters between day, month and year. In this case the input
- string must be exactly 6 or 8 bytes long but isn't.
+ ECPG_INFORMIX_ENOSHORTDATE> - The date does not contain
+ delimiters between day, month and year. In this case the input
+ string must be exactly 6 or 8 bytes long but isn't.
- ECPG_INFORMIX_ENOTDMY> - The format string did not
- correctly indicate the sequential order of year, month and day.
+ ECPG_INFORMIX_ENOTDMY> - The format string did not
+ correctly indicate the sequential order of year, month and day.
- ECPG_INFORMIX_BAD_DAY> - The input string does not
- contain a valid day.
+ ECPG_INFORMIX_BAD_DAY> - The input string does not
+ contain a valid day.
- ECPG_INFORMIX_BAD_MONTH> - The input string does not
- contain a valid month.
+ ECPG_INFORMIX_BAD_MONTH> - The input string does not
+ contain a valid month.
- ECPG_INFORMIX_BAD_YEAR> - The input string does not
- contain a valid year.
+ ECPG_INFORMIX_BAD_YEAR> - The input string does not
+ contain a valid year.
-
+
- Internally this function is implemented to use the
- linkend="PGTYPESdatedefmtasc"> function. See the reference there for a
- table of example input.
+
Internally this function is implemented to use the
+ linkend="PGTYPESdatedefmtasc"> function. See the reference there for a
+ table of example input.
rfmtdate>
- Convert a variable of type date to its textual representation using a
- format mask.
+ Convert a variable of type date to its textual representation using a
+ format mask.
int rfmtdate(date d, char *fmt, char *str);
- The function receives the date to convert (d>), the format
- mask (fmt>) and the string that will hold the textual
- representation of the date (str>).
+ The function receives the date to convert (d>), the format
+ mask (fmt>) and the string that will hold the textual
+ representation of the date (str>).
On success, 0 is returned and a negative value if an error occurred.
- Internally this function uses the
- function, see the reference there for examples.
+ Internally this function uses the
+ function, see the reference there for examples.
rmdyjul>
- Create a date value from an array of 3 short integers that specify the
- day, the month and the year of the date.
+ Create a date value from an array of 3 short integers that specify the
+ day, the month and the year of the date.
int rmdyjul(short mdy[3], date *d);
- The function receives the array of the 3 short integers
- (mdy>) and a pointer to a variable of type date that should
- hold the result of the operation.
+ The function receives the array of the 3 short integers
+ (mdy>) and a pointer to a variable of type date that should
+ hold the result of the operation.
Currently the function returns always 0.
- Internally the function is implemented to use the function
- linkend="PGTYPESdatemdyjul">.
+
Internally the function is implemented to use the function
+ linkend="PGTYPESdatemdyjul">.
int rdayofweek(date d);
- The function receives the date variable d> as its only
- argument and returns an integer that indicates the day of the week for
- this date.
+ The function receives the date variable d> as its only
+ argument and returns an integer that indicates the day of the week for
+ this date.
- 0 - Sunday
+ 0 - Sunday
- 1 - Monday
+ 1 - Monday
- 2 - Tuesday
+ 2 - Tuesday
- 3 - Wednesday
+ 3 - Wednesday
- 4 - Thursday
+ 4 - Thursday
- 5 - Friday
+ 5 - Friday
- 6 - Saturday
+ 6 - Saturday
- Internally the function is implemented to use the function
- linkend="PGTYPESdatedayofweek">.
+
Internally the function is implemented to use the function
+ linkend="PGTYPESdatedayofweek">.
void dtcurrent(timestamp *ts);
- The function retrieves the current timestamp and saves it into the
- timestamp variable that ts> points to.
+ The function retrieves the current timestamp and saves it into the
+ timestamp variable that ts> points to.
dtcvasc>
- Parses a timestamp from its textual representation in ANSI standard
- into a timestamp variable.
+ Parses a timestamp from its textual representation in ANSI standard
+ into a timestamp variable.
int dtcvasc(char *str, timestamp *ts);
- The function receives the string to parse (str>) and a
- pointer to the timestamp variable that should hold the result of the
- operation (ts>).
+ The function receives the string to parse (str>) and a
+ pointer to the timestamp variable that should hold the result of the
+ operation (ts>).
- The function returns 0 on success and a negative value in case of
- error.
+ The function returns 0 on success and a negative value in case of
+ error.
- Internally this function uses the
- linkend="PGTYPEStimestampfromasc"> function. See the reference there
- for a table with example inputs.
+
Internally this function uses the
+ linkend="PGTYPEStimestampfromasc"> function. See the reference there
+ for a table with example inputs.
dtcvfmtasc>
- Parses a timestamp from its textual representation in ANSI standard
- using a format mask into a timestamp variable.
+ Parses a timestamp from its textual representation in ANSI standard
+ using a format mask into a timestamp variable.
dtcvfmtasc(char *inbuf, char *fmtstr, timestamp *dtvalue)
- The function receives the string to parse (inbuf>), the
- format mask to use (fmtstr>) and a pointer to the timestamp
- variable that should hold the result of the operation (ts>).
+ The function receives the string to parse (inbuf>), the
+ format mask to use (fmtstr>) and a pointer to the timestamp
+ variable that should hold the result of the operation (ts>).
- This functions is implemented by means of the
- linkend="PGTYPEStimestampdefmtasc">. See the documentation
- there for a list of format specifiers that can be used.
+
This functions is implemented by means of the
+ linkend="PGTYPEStimestampdefmtasc">. See the documentation
+ there for a list of format specifiers that can be used.
- The function returns 0 on success and a negative value in case of
- error.
+ The function returns 0 on success and a negative value in case of
+ error.
dtsub>
- Subtract one timestamp from another and return a variable of type
- interval.
+ Subtract one timestamp from another and return a variable of type
+ interval.
int dtsub(timestamp *ts1, timestamp *ts2, interval *iv);
- The function will subtract the timestamp variable that ts2>
- points to from the timestamp variable that ts1> points to
- and will store the result in the interval variable that iv>
- points to.
+ The function will subtract the timestamp variable that ts2>
+ points to from the timestamp variable that ts1> points to
+ and will store the result in the interval variable that iv>
+ points to.
- Upon success, the function returns 0 and a negative value if an
- error occurred.
+ Upon success, the function returns 0 and a negative value if an
+ error occurred.
int dttoasc(timestamp *ts, char *output);
- The function receives a pointer to the timestamp variable to convert
- (ts>) and the string that should hold the result of the
- operation output>). It converts ts> to its
- textual representation in the ANSI SQL standard which is defined to
- be YYYY-MM-DD HH:MM:SS.
+ The function receives a pointer to the timestamp variable to convert
+ (ts>) and the string that should hold the result of the
+ operation output>). It converts ts> to its
+ textual representation in the ANSI SQL standard which is defined to
+ be YYYY-MM-DD HH:MM:SS.
- Upon success, the function returns 0 and a negative value if an
- error occurred.
+ Upon success, the function returns 0 and a negative value if an
+ error occurred.
int dttofmtasc(timestamp *ts, char *output, int str_len, char *fmtstr);
- The function receives a pointer to the timestamp to convert as its
- first argument (ts>), a pointer to the output buffer
- (output>), the maximal length that has been allocated for
- the output buffer (str_len) and the format mask to
- use for the conversion (fmtstr).
+ The function receives a pointer to the timestamp to convert as its
+ first argument (ts>), a pointer to the output buffer
+ (output>), the maximal length that has been allocated for
+ the output buffer (str_len) and the format mask to
+ use for the conversion (fmtstr).
- Upon success, the function returns 0 and a negative value if an
- error occurred.
+ Upon success, the function returns 0 and a negative value if an
+ error occurred.
- Internally, this function uses the
- linkend="PGTYPEStimestampfmtasc"> function. See the reference there for
- information on what format mask specifiers can be used.
+
Internally, this function uses the
+ linkend="PGTYPEStimestampfmtasc"> function. See the reference there for
+ information on what format mask specifiers can be used.
int intoasc(interval *i, char *str);
- The function receives a pointer to the interval variable to convert
- (i>) and the string that should hold the result of the
- operation str>). It converts i> to its
- textual representation in the ANSI SQL standard which is defined to
- be YYYY-MM-DD HH:MM:SS.
+ The function receives a pointer to the interval variable to convert
+ (i>) and the string that should hold the result of the
+ operation str>). It converts i> to its
+ textual representation in the ANSI SQL standard which is defined to
+ be YYYY-MM-DD HH:MM:SS.
- Upon success, the function returns 0 and a negative value if an
- error occurred.
+ Upon success, the function returns 0 and a negative value if an
+ error occurred.
rfmtlong>
- Convert a long integer value to its textual representation using a
- format mask.
+ Convert a long integer value to its textual representation using a
+ format mask.
int rfmtlong(long lng_val, char *fmt, char *outbuf);
- The function receives the long value lng_val>, the format
- mask fmt> and a pointer to the output buffer
- outbuf>. It converts the long value according to the format
- mask to its textual representation.
+ The function receives the long value lng_val>, the format
+ mask fmt> and a pointer to the output buffer
+ outbuf>. It converts the long value according to the format
+ mask to its textual representation.
- The format mask can be composed of the following format specifying
- characters:
+ The format mask can be composed of the following format specifying
+ characters:
- * (asterisk) - if this position would be blank
- otherwise, fill it with an asterisk.
+ * (asterisk) - if this position would be blank
+ otherwise, fill it with an asterisk.
- & (ampersand) - if this position would be
- blank otherwise, fill it with a zero.
+ & (ampersand) - if this position would be
+ blank otherwise, fill it with a zero.
- # - turn leading zeroes into blanks.
+ # - turn leading zeroes into blanks.
- < - left-justify the number in the string.
+ < - left-justify the number in the string.
- , (comma) - group numbers of four or more digits
- into groups of three digits separated by a comma.
+ , (comma) - group numbers of four or more digits
+ into groups of three digits separated by a comma.
- . (period) - this character separates the
- whole-number part of the number from the fractional part.
+ . (period) - this character separates the
+ whole-number part of the number from the fractional part.
- - (minus) - the minus sign appears if the number
- is a negative value.
+ - (minus) - the minus sign appears if the number
+ is a negative value.
- + (plus) - the plus sign appears if the number is
- a positive value.
+ + (plus) - the plus sign appears if the number is
+ a positive value.
- ( - this replaces the minus sign in front of the
- negative number. The minus sign will not appear.
+ ( - this replaces the minus sign in front of the
+ negative number. The minus sign will not appear.
- ) - this character replaces the minus and is
- printed behind the negative value.
+ ) - this character replaces the minus and is
+ printed behind the negative value.
- $ - the currency symbol.
+ $ - the currency symbol.
-
+
void rupshift(char *str);
- The function receives a pointer to the string and transforms every
- lower case character to upper case.
+ The function receives a pointer to the string and transforms every
+ lower case character to upper case.
byleng>
- Return the number of characters in a string without counting trailing
- blanks.
+ Return the number of characters in a string without counting trailing
+ blanks.
int byleng(char *str, int len);
- The function expects a fixed-length string as its first argument
- (str>) and its length as its second argument
- (len>). It returns the number of significant characters,
- that is the length of the string without trailing blanks.
+ The function expects a fixed-length string as its first argument
+ (str>) and its length as its second argument
+ (len>). It returns the number of significant characters,
+ that is the length of the string without trailing blanks.
void ldchar(char *src, int len, char *dest);
- The function receives the fixed-length string to copy
- (src>), its length (len>) and a pointer to the
- destination memory (dest>). Note that you need to reserve at
- least len+1> bytes for the string that dest>
- points to. The function copies at most len> bytes to the new
- location (less if the source string has trailing blanks) and adds the
- null-terminator.
+ The function receives the fixed-length string to copy
+ (src>), its length (len>) and a pointer to the
+ destination memory (dest>). Note that you need to reserve at
+ least len+1> bytes for the string that dest>
+ points to. The function copies at most len> bytes to the new
+ location (less if the source string has trailing blanks) and adds the
+ null-terminator.
int rsetnull(int t, char *ptr);
- The function receives an integer that indicates the type of the
- variable and a pointer to the variable itself that is casted to a C
- char* pointer.
+ The function receives an integer that indicates the type of the
+ variable and a pointer to the variable itself that is casted to a C
+ char* pointer.
The following types exist:
- CCHARTYPE - For a variable of type char or char*
+ CCHARTYPE - For a variable of type char or char*
- CSHORTTYPE - For a variable of type short int
+ CSHORTTYPE - For a variable of type short int
- CINTTYPE - For a variable of type int
+ CINTTYPE - For a variable of type int
- CBOOLTYPE - For a variable of type boolean
+ CBOOLTYPE - For a variable of type boolean
- CFLOATTYPE - For a variable of type float
+ CFLOATTYPE - For a variable of type float
- CLONGTYPE - For a variable of type long
+ CLONGTYPE - For a variable of type long
- CDOUBLETYPE - For a variable of type double
+ CDOUBLETYPE - For a variable of type double
- CDECIMALTYPE - For a variable of type decimal
+ CDECIMALTYPE - For a variable of type decimal
- CDATETYPE - For a variable of type date
+ CDATETYPE - For a variable of type date
- CDTIMETYPE - For a variable of type timestamp
+ CDTIMETYPE - For a variable of type timestamp
int risnull(int t, char *ptr);
- The function receives the type of the variable to test (t>)
- as well a pointer to this variable (ptr>). Note that the
- latter needs to be casted to a char*. See the function
- linkend="rsetnull"> for a list of possible variable types.
+ The function receives the type of the variable to test (t>)
+ as well a pointer to this variable (ptr>). Note that the
+
latter needs to be casted to a char*. See the function
+ linkend="rsetnull"> for a list of possible variable types.
Here is an example of how to use this function:
ECPG_INFORMIX_NUM_OVERFLOW>
- Functions return this value if an overflow occurred in a
- calculation. Internally it is defined to -1200 (the
Informix
- definition).
+ Functions return this value if an overflow occurred in a
+
calculation. Internally it is defined to -1200 (the
Informix
+ definition).
ECPG_INFORMIX_NUM_UNDERFLOW>
- Functions return this value if an underflow occurred in a calculation.
- Internally it is defined to -1201 (the
Informix definition).
+ Functions return this value if an underflow occurred in a calculation.
+
Internally it is defined to -1201 (the
Informix definition).
ECPG_INFORMIX_DIVIDE_ZERO>
- Functions return this value if an attempt to divide by zero is
- observed. Internally it is defined to -1202 (the
Informix definition).
+ Functions return this value if an attempt to divide by zero is
+
observed. Internally it is defined to -1202 (the
Informix definition).
ECPG_INFORMIX_BAD_YEAR>
- Functions return this value if a bad value for a year was found while
- parsing a date. Internally it is defined to -1204 (the
Informix
- definition).
+ Functions return this value if a bad value for a year was found while
+
parsing a date. Internally it is defined to -1204 (the
Informix
+ definition).
ECPG_INFORMIX_BAD_MONTH>
- Functions return this value if a bad value for a month was found while
- parsing a date. Internally it is defined to -1205 (the
Informix
- definition).
+ Functions return this value if a bad value for a month was found while
+
parsing a date. Internally it is defined to -1205 (the
Informix
+ definition).
ECPG_INFORMIX_BAD_DAY>
- Functions return this value if a bad value for a day was found while
- parsing a date. Internally it is defined to -1206 (the
Informix
- definition).
+ Functions return this value if a bad value for a day was found while
+
parsing a date. Internally it is defined to -1206 (the
Informix
+ definition).
ECPG_INFORMIX_ENOSHORTDATE>
- Functions return this value if a parsing routine needs a short date
- representation but did not get the date string in the right length.
- Internally it is defined to -1209 (the
Informix definition).
+ Functions return this value if a parsing routine needs a short date
+ representation but did not get the date string in the right length.
+
Internally it is defined to -1209 (the
Informix definition).
ECPG_INFORMIX_DATE_CONVERT>
- Functions return this value if Internally it is defined to -1210 (the
+ Functions return this value if Internally it is defined to -1210 (the
ECPG_INFORMIX_OUT_OF_MEMORY>
- Functions return this value if Internally it is defined to -1211 (the
+ Functions return this value if Internally it is defined to -1211 (the
ECPG_INFORMIX_ENOTDMY>
- Functions return this value if a parsing routine was supposed to get a
- format mask (like mmddyy>) but not all fields were listed
- correctly. Internally it is defined to -1212 (the
Informix definition).
+ Functions return this value if a parsing routine was supposed to get a
+ format mask (like mmddyy>) but not all fields were listed
+
correctly. Internally it is defined to -1212 (the
Informix definition).
ECPG_INFORMIX_BAD_NUMERIC>
- Functions return this value either if a parsing routine cannot parse
- the textual representation for a numeric value because it contains
- errors or if a routine cannot complete a calculation involving numeric
- variables because at least one of the numeric variables is invalid.
- Internally it is defined to -1213 (the
Informix definition).
+ Functions return this value either if a parsing routine cannot parse
+ the textual representation for a numeric value because it contains
+ errors or if a routine cannot complete a calculation involving numeric
+ variables because at least one of the numeric variables is invalid.
+
Internally it is defined to -1213 (the
Informix definition).
ECPG_INFORMIX_BAD_EXPONENT>
- Functions return this value if Internally it is defined to -1216 (the
+ Functions return this value if Internally it is defined to -1216 (the
ECPG_INFORMIX_BAD_DATE>
- Functions return this value if Internally it is defined to -1218 (the
+ Functions return this value if Internally it is defined to -1218 (the
ECPG_INFORMIX_EXTRA_CHARS>
- Functions return this value if Internally it is defined to -1264 (the
+ Functions return this value if Internally it is defined to -1264 (the
-
+
Functions and Operators
An ISO week date (as distinct from a Gregorian date) can be specified to to_timestamp and to_date in one of two ways:
- Year, week and weekday, for example to_date('2006-42-4', 'IYYY-IW-ID') returns the date 2006-10-19. If you omit the weekday it is assumed to be 1 (Monday).
-
-
-
- Year and day of year, for example to_date('2006-291', 'IYYY-IDDD') also returns 2006-10-19.
-
-
+ Year, week and weekday, for example to_date('2006-42-4', 'IYYY-IW-ID') returns the date 2006-10-19. If you omit the weekday it is assumed to be 1 (Monday).
+
+
+
+ Year and day of year, for example to_date('2006-291', 'IYYY-IDDD') also returns 2006-10-19.
+
+
-
+
PostgreSQL) to process individual joins
and a diversity of indexes (e.g.,
B-tree, hash, GiST and GIN in
PostgreSQL) as
- access paths for relations.
+ access paths for relations.
-
+
GIN Indexes
to consult n> to determine the data type of
query> and the key values that need to be extracted.
The number of returned keys must be stored into *nkeys>.
- If number of keys is equal to zero then extractQuery>
- should store 0 or -1 into *nkeys>. 0 means that any
- row matches the query> and sequence scan should be
- produced. -1 means nothing can satisfy query>.
- Choice of value should be based on semantics meaning of operation with
- given strategy number.
+ If number of keys is equal to zero then extractQuery>
+ should store 0 or -1 into *nkeys>. 0 means that any
+ row matches the query> and sequence scan should be
+ produced. -1 means nothing can satisfy query>.
+ Choice of value should be based on semantics meaning of operation with
+ given strategy number.
-
+
If the
dbName contains an
= sign, it
- is taken as a
conninfo string in exactly the same way as
- if it had been passed to PQconnectdb, and the remaining
- parameters are then applied as above.
+
is taken as a
conninfo string in exactly the same way as
+ if it had been passed to PQconnectdb, and the remaining
+ parameters are then applied as above.
do not reveal secret keys to the application. Instead, applications
delegate all cryptography operations which require the secret key to
the hardware token.
-
-
+
+
If the file ~/.postgresql/root.crt> is present in the user's
home directory,
-
+
Concurrency Control
- |
+ |
Modes
AS
RS
SRE
E
AE
-
-
-
- |
+
+
+
+ |
AS
Y
Y
Y
Y
N
-
- |
+
+ |
RS
Y
Y
Y
N
N
-
- |
+
+ |
RE
Y
Y
N
N
N
-
- |
+
+ |
SUE
Y
Y
N
N
N
-
- |
+
+ |
S
Y
Y
N
N
N
-
- |
+
+ |
SRE
Y
Y
N
N
N
-
- |
+
+ |
E
Y
N
N
N
N
-
- |
+
+ |
AE
N
N
N
N
N
-
-
-
-
+
+
+
+
-
+
PL/Perl - Perl Procedural Language
- For security reasons, to stop a leak of privileged operations from
+ For security reasons, to stop a leak of privileged operations from
PL/PerlU> to PL/Perl>, these two languages
- have to run in separate instances of the Perl interpreter. If your
- Perl installation has been appropriately compiled, this is not a problem.
- However, not all installations are compiled with the requisite flags.
- If
PostgreSQL> detects that this is the case then it will
- not start a second interpreter, but instead create an error. In
- consequence, in such an installation, you cannot use both
-
PL/PerlU> and PL/Perl> in the same backend
- process. The remedy for this is to obtain a Perl installation created
- with the appropriate flags, namely either usemultiplicity> or
- both usethreads> and useithreads>.
- For more details,see the perlembed> manual page.
+ have to run in separate instances of the Perl interpreter. If your
+ Perl installation has been appropriately compiled, this is not a problem.
+ However, not all installations are compiled with the requisite flags.
+
If
PostgreSQL> detects that this is the case then it will
+ not start a second interpreter, but instead create an error. In
+ consequence, in such an installation, you cannot use both
+
PL/PerlU> and PL/Perl> in the same backend
+ process. The remedy for this is to obtain a Perl installation created
+ with the appropriate flags, namely either usemultiplicity> or
+ both usethreads> and useithreads>.
+ For more details,see the perlembed> manual page.
-
+
SQL
- SELECT (σ): extracts tuples from
- a relation that
- satisfy a given restriction. Let
R be a
- table that contains an attribute
+ SELECT (σ): extracts tuples from
+ a relation that
+
satisfy a given restriction. Let
R be a
+ table that contains an attribute
σA=a(R) = {t ∈ R ∣ t(A) = a}
- where t denotes a
- denotes the value of attribute
A of
- tuple t.
+ where t denotes a
+
denotes the value of attribute
A of
+ tuple t.
- PROJECT (π): extracts specified
- attributes (columns) from a
- relation. Let R be a relation
- that contains an attribute X.
- πX(R) = {t(X) ∣ t ∈ R},
- where t(X) denotes the value of
- attribute X of tuple t.
+ PROJECT (π): extracts specified
+ attributes (columns) from a
+ relation. Let R be a relation
+ that contains an attribute X.
+ πX(R) = {t(X) ∣ t ∈ R},
+ where t(X) denotes the value of
+ attribute X of tuple t.
- PRODUCT (×): builds the Cartesian product of two
- relations. Let R be a table with arity
- k1 and let
- S be a table with
- arity k2.
- R × S
- is the set of all
- k1
- + k2-tuples
- whose first k1
- components form a tuple in R and whose last
- k2 components form a
- tuple in S.
+ PRODUCT (×): builds the Cartesian product of two
+ relations. Let R be a table with arity
+ k1 and let
+ S be a table with
+ arity k2.
+ R × S
+ is the set of all
+ k1
+ + k2-tuples
+ whose first k1
+ components form a tuple in R and whose last
+ k2 components form a
+ tuple in S.
- UNION (∪): builds the set-theoretic union of two
- tables. Given the tables R and
- S (both must have the same arity),
- the union R ∪ S
- is the set of tuples that are in R
- or S or both.
+ UNION (∪): builds the set-theoretic union of two
+ tables. Given the tables R and
+ S (both must have the same arity),
+ the union R ∪ S
+ is the set of tuples that are in R
+ or S or both.
- INTERSECT (∩): builds the set-theoretic intersection of two
- tables. Given the tables R and
- S,
- R ∩ S is the
- set of tuples
- that are in R and in
- S.
- We again require that R and
- S have the
- same arity.
+ INTERSECT (∩): builds the set-theoretic intersection of two
+ tables. Given the tables R and
+ S,
+ R ∩ S is the
+ set of tuples
+ that are in R and in
+ S.
+ We again require that R and
+ S have the
+ same arity.
- DIFFERENCE (− or ∖): builds the set difference of
- two tables. Let R and S
- again be two tables with the same
- arity. R - S
- is the set of tuples in R but not in
- S.
+ DIFFERENCE (− or ∖): builds the set difference of
+ two tables. Let R and S
+ again be two tables with the same
+ arity. R - S
+ is the set of tuples in R but not in
+ S.
- JOIN (∏): connects two tables by their common
- attributes. Let R be a table with the
- attributes A,B
- and C and
- let S be a table with the attributes
- C,D
- and E. There is one
- attribute common to both relations,
- the attribute C.
+ JOIN (∏): connects two tables by their common
+ attributes. Let R be a table with the
+ attributes A,B
+ and C and
+ let S be a table with the attributes
+ C,D
+ and E. There is one
+ attribute common to both relations,
+ the attribute C.
- R ∏ S = πR.A,R.B,R.C,S.D,S.E(σR.C=S.C(R × S)).
- What are we doing here? We first calculate the Cartesian
- product
- R × S.
- Then we select those tuples whose values for the common
- attribute C are equal
- (σR.C = S.C).
- Now we have a table
- that contains the attribute C
- two times and we correct this by
- projecting out the duplicate column.
+ R ∏ S = πR.A,R.B,R.C,S.D,S.E(σR.C=S.C(R × S)).
+ What are we doing here? We first calculate the Cartesian
+ product
+ R × S.
+ Then we select those tuples whose values for the common
+ attribute C are equal
+ (σR.C = S.C).
+ Now we have a table
+ that contains the attribute C
+ two times and we correct this by
+ projecting out the duplicate column.
-
An Inner Join
+
An Inner Join
- Let's have a look at the tables that are produced by evaluating the steps
- necessary for a join.
- Let the following two tables be given:
+ Let's have a look at the tables that are produced by evaluating the steps
+ necessary for a join.
+ Let the following two tables be given:
R: S:
A | B | C C | D | E
---+---+--- ---+---+---
1 | 2 | 3 3 | a | b
4 | 5 | 6 6 | c | d
7 | 8 | 9
-
-
+
+
- First we calculate the Cartesian product
- R × S and
- get:
+ First we calculate the Cartesian product
+ R × S and
+ get:
R x S:
A | B | R.C | S.C | D | E
---+---+-----+-----+---+---
4 | 5 | 6 | 6 | c | d
7 | 8 | 9 | 3 | a | b
7 | 8 | 9 | 6 | c | d
-
+
- After the selection
- σR.C=S.C(R × S)
- we get:
+ After the selection
+ σR.C=S.C(R × S)
+ we get:
A | B | R.C | S.C | D | E
---+---+-----+-----+---+---
1 | 2 | 3 | 3 | a | b
4 | 5 | 6 | 6 | c | d
-
+
- To remove the duplicate column
- S.C
- we project it out by the following operation:
- πR.A,R.B,R.C,S.D,S.E(σR.C=S.C(R × S))
- and get:
+ To remove the duplicate column
+ S.C
+ we project it out by the following operation:
+ πR.A,R.B,R.C,S.D,S.E(σR.C=S.C(R × S))
+ and get:
A | B | C | D | E
---+---+---+---+---
1 | 2 | 3 | a | b
4 | 5 | 6 | c | d
-
+
- DIVIDE (÷): Let R be a table
- with the attributes A, B, C, and D and let
- S be a table with the attributes
- C and D.
- Then we define the division as:
+ DIVIDE (÷): Let R be a table
+ with the attributes A, B, C, and D and let
+ S be a table with the attributes
+ C and D.
+ Then we define the division as:
R ÷ S = {t ∣ ∀ ts ∈ S ∃ tr ∈ R
-
+
- such that
+ such that
tr(A,B)=t∧tr(C,D)=ts}
- where
- tr(x,y)
- denotes a
- tuple of table R that consists only of
- the components x and y.
- Note that the tuple t only consists of the
- components A and
- B of relation R.
+ where
+ tr(x,y)
+ denotes a
+ tuple of table R that consists only of
+ the components x and y.
+ Note that the tuple t only consists of the
+ components A and
+ B of relation R.
- Given the following tables
+ Given the following tables
R: S:
A | B | C | D C | D
---+---+---+--- ---+---
e | d | c | d
e | d | e | f
a | b | d | e
-
+
- R ÷ S
- is derived as
+ R ÷ S
+ is derived as
A | B
---+---
a | b
e | d
-
+
- The Domain Relational Calculus
- stand for components (attributes) of the tuples.
+ The Domain Relational Calculus
+ stand for components (attributes) of the tuples.
- The Tuple Relational Calculus
- (
TRC), where variables stand for tuples.
+ The Tuple Relational Calculus
+
(
TRC), where variables stand for tuples.
Simple Query with Qualification
- To retrieve all tuples from table PART where the attribute PRICE is
- greater than 10 we formulate the following query:
+ To retrieve all tuples from table PART where the attribute PRICE is
+ greater than 10 we formulate the following query:
SELECT * FROM PART
WHERE PRICE > 10;
-
+
- and get the table:
+ and get the table:
PNO | PNAME | PRICE
-----+---------+--------
3 | Bolt | 15
4 | Cam | 25
-
+
- Using *
in the SELECT statement
- will deliver all attributes from the table. If we want to retrieve
- only the attributes PNAME and PRICE from table PART we use the
- statement:
+ Using *
in the SELECT statement
+ will deliver all attributes from the table. If we want to retrieve
+ only the attributes PNAME and PRICE from table PART we use the
+ statement:
SELECT PNAME, PRICE
FROM PART
WHERE PRICE > 10;
-
+
- In this case the result is:
+ In this case the result is:
PNAME | PRICE
--------+--------
Bolt | 15
Cam | 25
-
+
- Note that the
SQL SELECT
- corresponds to the projection
in relational algebra
- not to the
selection
(see
- endterm="rel-alg"> for more details).
+
Note that the
SQL SELECT
+ corresponds to the projection
in relational algebra
+
not to the
selection
(see
+ endterm="rel-alg"> for more details).
- The qualifications in the WHERE clause can also be logically connected
- using the keywords OR, AND, and NOT:
+ The qualifications in the WHERE clause can also be logically connected
+ using the keywords OR, AND, and NOT:
SELECT PNAME, PRICE
FROM PART
WHERE PNAME = 'Bolt' AND
(PRICE = 0 OR PRICE <= 15);
-
+
- will lead to the result:
+ will lead to the result:
PNAME | PRICE
--------+--------
Bolt | 15
-
+
- Arithmetic operations can be used in the target list and in the WHERE
- clause. For example if we want to know how much it would cost if we
- take two pieces of a part we could use the following query:
+ Arithmetic operations can be used in the target list and in the WHERE
+ clause. For example if we want to know how much it would cost if we
+ take two pieces of a part we could use the following query:
SELECT PNAME, PRICE * 2 AS DOUBLE
FROM PART
WHERE PRICE * 2 < 50;
-
+
- and we get:
+ and we get:
PNAME | DOUBLE
--------+---------
Screw | 20
Nut | 16
Bolt | 30
-
-
- Note that the word DOUBLE after the keyword AS is the new title of the
- second column. This technique can be used for every element of the
- target list to assign a new title to the resulting
- column. This new title
- is often referred to as alias. The alias cannot be used throughout the
- rest of the query.
+
+
+ Note that the word DOUBLE after the keyword AS is the new title of the
+ second column. This technique can be used for every element of the
+ target list to assign a new title to the resulting
+ column. This new title
+ is often referred to as alias. The alias cannot be used throughout the
+ rest of the query.
columns but S.SNAME and P.PNAME.
- Another way to perform joins is to use the SQL JOIN syntax as follows:
+ Another way to perform joins is to use the SQL JOIN syntax as follows:
select sname, pname from supplier
- JOIN sells USING (sno)
- JOIN part USING (pno);
-
- giving again:
+ JOIN sells USING (sno)
+ JOIN part USING (pno);
+
+ giving again:
sname | pname
-------+-------
Smith | Screw
Jones | Cam
Blake | Cam
(8 rows)
-
-
-
- A joined table, created using JOIN syntax, is a table reference list
- item that occurs in a FROM clause and before any WHERE, GROUP BY,
- or HAVING clause. Other table references, including table names or
- other JOIN clauses, can be included in the FROM clause if separated
- by commas. JOINed tables are logically like any other
- table listed in the FROM clause.
-
-
- SQL JOINs come in two main types, CROSS JOINs (unqualified joins)
- and qualified JOINs>. Qualified joins can be further
- subdivided based on the way in which the join condition>
- is specified (ON, USING, or NATURAL) and the way in which it is
- applied (INNER or OUTER join).
-
+
+
+
+ A joined table, created using JOIN syntax, is a table reference list
+ item that occurs in a FROM clause and before any WHERE, GROUP BY,
+ or HAVING clause. Other table references, including table names or
+ other JOIN clauses, can be included in the FROM clause if separated
+ by commas. JOINed tables are logically like any other
+ table listed in the FROM clause.
+
+
+ SQL JOINs come in two main types, CROSS JOINs (unqualified joins)
+ and qualified JOINs>. Qualified joins can be further
+ subdivided based on the way in which the join condition>
+ is specified (ON, USING, or NATURAL) and the way in which it is
+ applied (INNER or OUTER join).
+
Join Types
CROSS JOIN
-
-
- CROSS JOIN
+
+
+ CROSS JOIN
+
+
+ A cross join takes two tables T1 and T2 having N and M rows
+ respectively, and returns a joined table containing all
+ N*M possible joined rows. For each row R1 of T1, each row
+ R2 of T2 is joined with R1 to yield a joined table row JR
+ consisting of all fields in R1 and R2. A CROSS JOIN is
+ equivalent to an INNER JOIN ON TRUE.
+
+
+
+
+
+ Qualified JOINs
+
+
+
+
+
+
+
+
+ JOIN
+
+
USING ( join column list )
+
- A cross join takes two tables T1 and T2 having N and M rows
- respectively, and returns a joined table containing all
- N*M possible joined rows. For each row R1 of T1, each row
- R2 of T2 is joined with R1 to yield a joined table row JR
- consisting of all fields in R1 and R2. A CROSS JOIN is
- equivalent to an INNER JOIN ON TRUE.
-
-
-
-
-
- Qualified JOINs
-
-
-
-
-
-
-
-
- JOIN
-
-
USING ( join column list )
-
-
-
- A qualified JOIN must specify its join condition
- by providing one (and only one) of NATURAL, ON, or
- USING. The ON clause
- takes a search condition,
- which is the same as in a WHERE clause. The USING
- clause takes a comma-separated list of column names,
- which the joined tables must have in common, and joins
- the tables on equality of those columns. NATURAL is
- shorthand for a USING clause that lists all the common
- column names of the two tables. A side-effect of both
- USING and NATURAL is that only one copy of each joined
- column is emitted into the result table (compare the
- relational-algebra definition of JOIN, shown earlier).
-
-
-
-
-
-
-
- JOIN
-
-
-
- For each row R1 of T1, the joined table has a row for each row
- in T2 that satisfies the join condition with R1.
-
-
- The words INNER and OUTER are optional for all JOINs.
- INNER is the default. LEFT, RIGHT, and FULL imply an
- OUTER JOIN.
-
-
-
-
-
-
-
- JOIN
-
-
-
+ A qualified JOIN must specify its join condition
+ by providing one (and only one) of NATURAL, ON, or
+ USING. The ON clause
+ takes a search condition,
+ which is the same as in a WHERE clause. The USING
+ clause takes a comma-separated list of column names,
+ which the joined tables must have in common, and joins
+ the tables on equality of those columns. NATURAL is
+ shorthand for a USING clause that lists all the common
+ column names of the two tables. A side-effect of both
+ USING and NATURAL is that only one copy of each joined
+ column is emitted into the result table (compare the
+ relational-algebra definition of JOIN, shown earlier).
+
+
+
+
+
+
+
+ JOIN
+
+
+
+ For each row R1 of T1, the joined table has a row for each row
+ in T2 that satisfies the join condition with R1.
+
+
+ The words INNER and OUTER are optional for all JOINs.
+ INNER is the default. LEFT, RIGHT, and FULL imply an
+ OUTER JOIN.
+
+
+
+
+
+
+
+ JOIN
+
+
+
First, an INNER JOIN is performed.
Then, for each row in T1 that does not satisfy the join
- condition with any row in T2, an additional joined row is
- returned with null fields in the columns from T2.
-
-
- The joined table unconditionally has a row for each row in T1.
-
-
-
-
-
-
-
- JOIN
-
-
-
+ condition with any row in T2, an additional joined row is
+ returned with null fields in the columns from T2.
+
+
+ The joined table unconditionally has a row for each row in T1.
+
+
+
+
+
+
+
+ JOIN
+
+
+
First, an INNER JOIN is performed.
Then, for each row in T2 that does not satisfy the join
- condition with any row in T1, an additional joined row is
- returned with null fields in the columns from T1.
-
-
- The joined table unconditionally has a row for each row in T2.
-
-
-
-
-
-
-
- JOIN
-
-
-
+ condition with any row in T1, an additional joined row is
+ returned with null fields in the columns from T1.
+
+
+ The joined table unconditionally has a row for each row in T2.
+
+
+
+
+
+
+
+ JOIN
+
+
+
First, an INNER JOIN is performed.
Then, for each row in T1 that does not satisfy the join
- condition with any row in T2, an additional joined row is
- returned with null fields in the columns from T2.
+ condition with any row in T2, an additional joined row is
+ returned with null fields in the columns from T2.
Also, for each row in T2 that does not satisfy the join
- condition with any row in T1, an additional joined row is
- returned with null fields in the columns from T1.
-
-
- The joined table unconditionally has a row for every row of T1
- and a row for every row of T2.
-
-
-
-
-
-
-
-
+ condition with any row in T1, an additional joined row is
+ returned with null fields in the columns from T1.
+
+
+ The joined table unconditionally has a row for every row of T1
+ and a row for every row of T2.
+
+
+
+
+
+
+
+
-
+
- JOINs of all types can be chained together or nested where either or both of
- T1 and
- T2 can be JOINed tables.
- Parenthesis can be used around JOIN clauses to control the order
- of JOINs which are otherwise processed left to right.
-
+ JOINs of all types can be chained together or nested where either or both of
+ T1 and
+ T2 can be JOINed tables.
+ Parenthesis can be used around JOIN clauses to control the order
+ of JOINs which are otherwise processed left to right.
+
Aggregates
- If we want to know the average cost of all parts in table PART we use
- the following query:
+ If we want to know the average cost of all parts in table PART we use
+ the following query:
SELECT AVG(PRICE) AS AVG_PRICE
FROM PART;
-
+
- The result is:
+ The result is:
AVG_PRICE
-----------
14.5
-
+
- If we want to know how many parts are defined in table PART we use
- the statement:
+ If we want to know how many parts are defined in table PART we use
+ the statement:
SELECT COUNT(PNO)
FROM PART;
-
+
- and get:
+ and get:
COUNT
-------
4
-
+
Aggregates
- If we want to know how many parts are sold by every supplier we
- formulate the query:
+ If we want to know how many parts are sold by every supplier we
+ formulate the query:
SELECT S.SNO, S.SNAME, COUNT(SE.PNO)
FROM SUPPLIER S, SELLS SE
WHERE S.SNO = SE.SNO
GROUP BY S.SNO, S.SNAME;
-
+
- and get:
+ and get:
SNO | SNAME | COUNT
-----+-------+-------
1 | Smith | 2
2 | Jones | 1
3 | Adams | 2
4 | Blake | 3
-
+
- Now let's have a look of what is happening here.
- First the join of the
- tables SUPPLIER and SELLS is derived:
+ Now let's have a look of what is happening here.
+ First the join of the
+ tables SUPPLIER and SELLS is derived:
S.SNO | S.SNAME | SE.PNO
-------+---------+--------
1 | Smith | 1
4 | Blake | 2
4 | Blake | 3
4 | Blake | 4
-
+
- Next we partition the tuples into groups by putting all tuples
- together that agree on both attributes S.SNO and S.SNAME:
+ Next we partition the tuples into groups by putting all tuples
+ together that agree on both attributes S.SNO and S.SNAME:
S.SNO | S.SNAME | SE.PNO
-------+---------+--------
1 | Smith | 1
4 | Blake | 2
| 3
| 4
-
+
- In our example we got four groups and now we can apply the aggregate
- function COUNT to every group leading to the final result of the query
- given above.
+ In our example we got four groups and now we can apply the aggregate
+ function COUNT to every group leading to the final result of the query
+ given above.
Having
- If we want only those suppliers selling more than one part we use the
- query:
+ If we want only those suppliers selling more than one part we use the
+ query:
SELECT S.SNO, S.SNAME, COUNT(SE.PNO)
FROM SUPPLIER S, SELLS SE
WHERE S.SNO = SE.SNO
GROUP BY S.SNO, S.SNAME
HAVING COUNT(SE.PNO) > 1;
-
+
- and get:
+ and get:
SNO | SNAME | COUNT
-----+-------+-------
1 | Smith | 2
3 | Adams | 2
4 | Blake | 3
-
+
Subselect
- If we want to know all parts having a greater price than the part
- named 'Screw' we use the query:
+ If we want to know all parts having a greater price than the part
+ named 'Screw' we use the query:
SELECT *
FROM PART
WHERE PRICE > (SELECT PRICE FROM PART
WHERE PNAME='Screw');
-
+
- The result is:
+ The result is:
PNO | PNAME | PRICE
-----+---------+--------
3 | Bolt | 15
4 | Cam | 25
-
+
- When we look at the above query we can see the keyword
- SELECT two times. The first one at the
- beginning of the query - we will refer to it as outer
- SELECT - and the one in the WHERE clause which
- begins a nested query - we will refer to it as inner
- SELECT. For every tuple of the outer
- SELECT the inner SELECT has
- to be evaluated. After every evaluation we know the price of the
- tuple named 'Screw' and we can check if the price of the actual
- tuple is greater. (Actually, in this example the inner query need
- only be evaluated once, since it does not depend on the state of
- the outer query.)
+ When we look at the above query we can see the keyword
+ SELECT two times. The first one at the
+ beginning of the query - we will refer to it as outer
+ SELECT - and the one in the WHERE clause which
+ begins a nested query - we will refer to it as inner
+ SELECT. For every tuple of the outer
+ SELECT the inner SELECT has
+ to be evaluated. After every evaluation we know the price of the
+ tuple named 'Screw' and we can check if the price of the actual
+ tuple is greater. (Actually, in this example the inner query need
+ only be evaluated once, since it does not depend on the state of
+ the outer query.)
- If we want to know all suppliers that do not sell any part
- (e.g. to be able to remove these suppliers from the database) we use:
+ If we want to know all suppliers that do not sell any part
+ (e.g. to be able to remove these suppliers from the database) we use:
SELECT *
FROM SUPPLIER S
WHERE NOT EXISTS
(SELECT * FROM SELLS SE
WHERE SE.SNO = S.SNO);
-
+
- In our example the result will be empty because every supplier
- sells at least one part. Note that we use S.SNO from the outer
- SELECT within the WHERE clause of the inner
- SELECT. Here the subquery must be evaluated
- afresh for each tuple from the outer query, i.e. the value for
- S.SNO is always taken from the current tuple of the outer
- SELECT.
+ In our example the result will be empty because every supplier
+ sells at least one part. Note that we use S.SNO from the outer
+ SELECT within the WHERE clause of the inner
+ SELECT. Here the subquery must be evaluated
+ afresh for each tuple from the outer query, i.e. the value for
+ S.SNO is always taken from the current tuple of the outer
+ SELECT.
If we want to know the highest average part price among all our
- suppliers, we cannot write MAX(AVG(PRICE)), but we can write:
+ suppliers, we cannot write MAX(AVG(PRICE)), but we can write:
SELECT MAX(subtable.avgprice)
FROM (SELECT AVG(P.PRICE) AS avgprice
FROM SUPPLIER S, PART P, SELLS SE
WHERE S.SNO = SE.SNO AND
P.PNO = SE.PNO
GROUP BY S.SNO) subtable;
-
+
- The subquery returns one row per supplier (because of its GROUP BY)
- and then we aggregate over those rows in the outer query.
+ The subquery returns one row per supplier (because of its GROUP BY)
+ and then we aggregate over those rows in the outer query.
Union, Intersect, Except
- The following query is an example for UNION:
+ The following query is an example for UNION:
SELECT S.SNO, S.SNAME, S.CITY
FROM SUPPLIER S
WHERE S.SNAME = 'Jones'
SELECT S.SNO, S.SNAME, S.CITY
FROM SUPPLIER S
WHERE S.SNAME = 'Adams';
-
+
gives the result:
SNO | SNAME | CITY
-----+-------+--------
2 | Jones | Paris
3 | Adams | Vienna
-
+
- Here is an example for INTERSECT:
+ Here is an example for INTERSECT:
SELECT S.SNO, S.SNAME, S.CITY
FROM SUPPLIER S
WHERE S.SNO > 1
SELECT S.SNO, S.SNAME, S.CITY
FROM SUPPLIER S
WHERE S.SNO < 3;
-
+
- gives the result:
+ gives the result:
SNO | SNAME | CITY
-----+-------+--------
2 | Jones | Paris
-
+
- The only tuple returned by both parts of the query is the one having SNO=2.
+ The only tuple returned by both parts of the query is the one having SNO=2.
- Finally an example for EXCEPT:
+ Finally an example for EXCEPT:
SELECT S.SNO, S.SNAME, S.CITY
FROM SUPPLIER S
WHERE S.SNO > 1
SELECT S.SNO, S.SNAME, S.CITY
FROM SUPPLIER S
WHERE S.SNO > 3;
-
+
- gives the result:
+ gives the result:
SNO | SNAME | CITY
-----+-------+--------
2 | Jones | Paris
3 | Adams | Vienna
-
+
Table Creation
- To create the tables defined in
- the
- following
SQL statements are used:
+ To create the tables defined in
+ the
+
following
SQL statements are used:
CREATE TABLE SUPPLIER
(SNO INTEGER,
SNAME VARCHAR(20),
CREATE TABLE SELLS
(SNO INTEGER,
PNO INTEGER);
-
+
- INTEGER: signed fullword binary integer (31 bits precision).
-
+ INTEGER: signed fullword binary integer (31 bits precision).
+
- SMALLINT: signed halfword binary integer (15 bits precision).
-
+ SMALLINT: signed halfword binary integer (15 bits precision).
+
- DECIMAL (p[,q]):
- signed packed decimal number of up to
- p
- digits, with
- q
- digits to the right of the decimal point.
- If q
- is omitted it is assumed to be 0.
-
+ DECIMAL (p[,q]):
+ signed packed decimal number of up to
+ p
+ digits, with
+ q
+ digits to the right of the decimal point.
+ If q
+ is omitted it is assumed to be 0.
+
- FLOAT: signed doubleword floating point number.
-
+ FLOAT: signed doubleword floating point number.
+
- VARCHAR(n):
- varying length character string of maximum length
- n.
-
+ VARCHAR(n):
+ varying length character string of maximum length
+ n.
+
- CHAR(n):
- fixed length character string of length
- n.
-
+ CHAR(n):
+ fixed length character string of length
+ n.
+
Create Index
- To create an index named I on attribute SNAME of relation SUPPLIER
- we use the following statement:
+ To create an index named I on attribute SNAME of relation SUPPLIER
+ we use the following statement:
CREATE INDEX I ON SUPPLIER (SNAME);
- The created index is maintained automatically, i.e. whenever a new
- tuple is inserted into the relation SUPPLIER the index I is
- adapted. Note that the only changes a user can perceive when an
- index is present are increased speed for SELECT
- and decreases in speed of updates.
+ The created index is maintained automatically, i.e. whenever a new
+ tuple is inserted into the relation SUPPLIER the index I is
+ adapted. Note that the only changes a user can perceive when an
+ index is present are increased speed for SELECT
+ and decreases in speed of updates.
- There are queries that cannot be formulated using pure
SQL
- (i.e. recursive queries). To be able to perform such queries we need a
- host language with a greater expressive power than
+
There are queries that cannot be formulated using pure
SQL
+ (i.e. recursive queries). To be able to perform such queries we need a
+ host language with a greater expressive power than
- We simply want to access a database from some application that
- is written in the host language (e.g. a ticket reservation system
- with a graphical user interface is written in C and the information
- about which tickets are still left is stored in a database that can be
- accessed using embedded
SQL).
+ We simply want to access a database from some application that
+ is written in the host language (e.g. a ticket reservation system
+ with a graphical user interface is written in C and the information
+ about which tickets are still left is stored in a database that can be
+
accessed using embedded
SQL).