Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitebdfac3

Browse files
committed
the patch include:
- rename ichar() to chr() (discussed with Tom) - add docs for oracle compatible routines: btrim() ascii() chr() repeat() - fix bug with timezone in to_char() - all to_char() variants return NULL instead textin("") if it's needful. The contrib/odbc is without changes and contains same routines as maintree ... because I not sure how plans are Thomas with this :-) Karel---------------------------------------------------------------------------This effectively one line patch should fix the fact thatforeign key definitions in create table were erroring ifa primary key was defined. I was using the columnslist to get the columns of the table for comparison, butit got reused as a temporary list inside the primary keystuff.Stephan Szabo
1 parent516aac4 commitebdfac3

File tree

5 files changed

+102
-28
lines changed

5 files changed

+102
-28
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,16 @@
356356
</thead>
357357
<tbody>
358358
<row>
359-
<entry>to_ascii(text [,name|int])</entry>
359+
<entry>ascii(text)</entry>
360+
<entry>int</entry>
361+
<entry>returns the decimal representation of the first character from text</entry>
362+
<entry>ascii('x')</entry>
363+
</row>
364+
<row>
365+
<entry>btrim(text,set)</entry>
360366
<entry>text</entry>
361-
<entry>convert text from multibyte encoding to ASCII</entry>
362-
<entry>to_ascii('Karel')</entry>
367+
<entry>both (left and right) trim characters from text</entry>
368+
<entry>btrim('xxxtrimxxx','x')</entry>
363369
</row>
364370
<row>
365371
<entry>char(text)</entry>
@@ -374,6 +380,12 @@
374380
<entry>char(varchar 'varchar string')</entry>
375381
</row>
376382
<row>
383+
<row>
384+
<entry>chr(int)</entry>
385+
<entry>text</entry>
386+
<entry>returns the character having the binary equivalent to int</entry>
387+
<entry>chr(65)</entry>
388+
</row>
377389
<entry>initcap(text)</entry>
378390
<entry>text</entry>
379391
<entry>first letter of each word to upper case</entry>
@@ -392,10 +404,10 @@
392404
<entry>ltrim('xxxxtrim','x')</entry>
393405
</row>
394406
<row>
395-
<entry>textpos(text,text)</entry>
407+
<entry>repeat(text,int)</entry>
396408
<entry>text</entry>
397-
<entry>locate specified substring</entry>
398-
<entry>position('high','ig')</entry>
409+
<entry>repeat text by int</entry>
410+
<entry>repeat('Pg', 4)</entry>
399411
</row>
400412
<row>
401413
<entry>rpad(text,int,text)</entry>
@@ -427,12 +439,24 @@
427439
<entry>convert varchar to text type</entry>
428440
<entry>text(varchar 'varchar string')</entry>
429441
</row>
442+
<row>
443+
<entry>textpos(text,text)</entry>
444+
<entry>text</entry>
445+
<entry>locate specified substring</entry>
446+
<entry>position('high','ig')</entry>
447+
</row>
448+
<row>
449+
<entry>to_ascii(text [,name|int])</entry>
450+
<entry>text</entry>
451+
<entry>convert text from multibyte encoding to ASCII</entry>
452+
<entry>to_ascii('Karel')</entry>
453+
</row>
430454
<row>
431455
<entry>translate(text,from,to)</entry>
432456
<entry>text</entry>
433457
<entry>convert character in string</entry>
434458
<entry>translate('12345', '1', 'a')</entry>
435-
</row>
459+
</row>
436460
<row>
437461
<entry>varchar(char)</entry>
438462
<entry>varchar</entry>

‎src/backend/parser/analyze.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
*$Id: analyze.c,v 1.157 2000/09/12 21:07:00 tgl Exp $
9+
*$Id: analyze.c,v 1.158 2000/09/25 12:58:46 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -1083,7 +1083,7 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
10831083
foreach(fkattrs,fkconstraint->fk_attrs) {
10841084
found=0;
10851085
fkattr=lfirst(fkattrs);
1086-
foreach(cols,columns) {
1086+
foreach(cols,stmt->tableElts) {
10871087
col=lfirst(cols);
10881088
if (strcmp(col->colname,fkattr->name)==0) {
10891089
found=1;

‎src/backend/utils/adt/formatting.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* -----------------------------------------------------------------------
22
* formatting.c
33
*
4-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.21 2000/08/29 04:41:47 momjian Exp $
4+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.22 2000/09/25 12:58:47 momjian Exp $
55
*
66
*
77
* Portions Copyright (c) 1999-2000, PostgreSQL, Inc
@@ -1742,7 +1742,7 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node)
17421742
break;
17431743
caseDCH_tz:
17441744
caseDCH_TZ:
1745-
if (flag==TO_CHAR)
1745+
if (flag==TO_CHAR&&tzn)
17461746
{
17471747
intsiz=strlen(tzn);
17481748

@@ -2452,7 +2452,7 @@ timestamp_to_char(PG_FUNCTION_ARGS)
24522452
len=VARSIZE(fmt)-VARHDRSZ;
24532453

24542454
if (len <=0||TIMESTAMP_NOT_FINITE(dt))
2455-
returnDirectFunctionCall1(textin,CStringGetDatum(""));
2455+
PG_RETURN_NULL();
24562456

24572457
ZERO_tm(tm);
24582458
tzn=NULL;
@@ -2552,7 +2552,12 @@ timestamp_to_char(PG_FUNCTION_ARGS)
25522552
* needs, now it must be re-allocate to result real size
25532553
* ----------
25542554
*/
2555-
len=strlen(VARDATA(result));
2555+
if (!(len=strlen(VARDATA(result))))
2556+
{
2557+
pfree(result);
2558+
PG_RETURN_NULL();
2559+
}
2560+
25562561
result_tmp=result;
25572562
result= (text*)palloc(len+1+VARHDRSZ);
25582563

@@ -4017,12 +4022,17 @@ do { \
40174022
if (flag)\
40184023
pfree(format);\
40194024
\
4020-
/* ----------\
4025+
/* ----------\
40214026
* for result is allocated max memory, which current format-picture\
40224027
* needs, now it must be re-allocate to result real size\
40234028
* ----------\
40244029
*/\
4025-
len=strlen(VARDATA(result));\
4030+
if (!(len=strlen(VARDATA(result))))\
4031+
{\
4032+
pfree(result);\
4033+
PG_RETURN_NULL();\
4034+
}\
4035+
\
40264036
result_tmp=result;\
40274037
result= (text*)palloc(len+1+VARHDRSZ);\
40284038
\

‎src/backend/utils/adt/oracle_compat.c

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
*Edmund Mergl <E.Mergl@bawue.de>
33
*
4-
*$Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.27 2000/07/06 05:48:11 tgl Exp $
4+
*$Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.28 2000/09/25 12:58:47 momjian Exp $
55
*
66
*/
77

@@ -515,6 +515,20 @@ translate(PG_FUNCTION_ARGS)
515515
PG_RETURN_TEXT_P(result);
516516
}
517517

518+
/********************************************************************
519+
*
520+
* ascii
521+
*
522+
* Syntax:
523+
*
524+
* int ascii(text string)
525+
*
526+
* Purpose:
527+
*
528+
* Returns the decimal representation of the first character from
529+
* string.
530+
*
531+
********************************************************************/
518532

519533
Datum
520534
ascii(PG_FUNCTION_ARGS)
@@ -527,12 +541,25 @@ ascii(PG_FUNCTION_ARGS)
527541
PG_RETURN_INT32((int32)*((unsignedchar*)VARDATA(string)));
528542
}
529543

544+
/********************************************************************
545+
*
546+
* chr
547+
*
548+
* Syntax:
549+
*
550+
* text chr(int val)
551+
*
552+
* Purpose:
553+
*
554+
*Returns the character having the binary equivalent to val
555+
*
556+
********************************************************************/
530557

531558
Datum
532-
ichar(PG_FUNCTION_ARGS)
559+
chr(PG_FUNCTION_ARGS)
533560
{
534-
int32cvalue=PG_GETARG_INT32(0);
535-
text*result;
561+
int32cvalue=PG_GETARG_INT32(0);
562+
text*result;
536563

537564
result= (text*)palloc(VARHDRSZ+1);
538565
VARATT_SIZEP(result)=VARHDRSZ+1;
@@ -541,17 +568,30 @@ ichar(PG_FUNCTION_ARGS)
541568
PG_RETURN_TEXT_P(result);
542569
}
543570

571+
/********************************************************************
572+
*
573+
* repeat
574+
*
575+
* Syntax:
576+
*
577+
* text repeat(text string, int val)
578+
*
579+
* Purpose:
580+
*
581+
*Repeat string by val.
582+
*
583+
********************************************************************/
544584

545585
Datum
546586
repeat(PG_FUNCTION_ARGS)
547587
{
548-
text*string=PG_GETARG_TEXT_P(0);
549-
int32count=PG_GETARG_INT32(1);
550-
text*result;
551-
intslen,
552-
tlen;
553-
inti;
554-
char*cp;
588+
text*string=PG_GETARG_TEXT_P(0);
589+
int32count=PG_GETARG_INT32(1);
590+
text*result;
591+
intslen,
592+
tlen;
593+
inti;
594+
char*cp;
555595

556596
if (count<0)
557597
count=0;

‎src/include/catalog/pg_proc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_proc.h,v 1.167 2000/09/19 18:18:01 petere Exp $
10+
* $Id: pg_proc.h,v 1.168 2000/09/25 12:58:47 momjian Exp $
1111
*
1212
* NOTES
1313
* The script catalog/genbki.sh reads this file and generates .bki
@@ -2036,7 +2036,7 @@ DESCR("convert int4 to varchar");
20362036

20372037
DATA(insertOID=1620 (asciiPGUID12fttt1f23"25"10000100ascii- ));
20382038
DESCR("convert first char to int4");
2039-
DATA(insertOID=1621 (icharPGUID12fttt1f25"23"10000100ichar- ));
2039+
DATA(insertOID=1621 (chrPGUID12fttt1f25"23"10000100chr- ));
20402040
DESCR("convert int4 to char");
20412041
DATA(insertOID=1622 (repeatPGUID12fttt2f25"25 23"10000100repeat- ));
20422042
DESCR("replicate string int4 times");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp