patch for implementing SPI_gettypemod()
Hi All,
This is regarding the TODO item :
"Add SPI_gettypmod() to return a field's typemod from a TupleDesc"
The related message is:
http://archives.postgresql.org/pgsql-hackers/2005-11/msg00250.php
This basically talks about having an SPI_gettypemod() which returns the
typmod of a field of tupdesc
Please refer the attached patch based on the suggested implementation.
Regards,
Chetan
--
EnterpriseDB Corporation
The Enterprise PostgreSQL Company
Website: www.enterprisedb.com
EnterpriseDB Blog : http://blogs.enterprisedb.com
Follow us on Twitter : http://www.twitter.com/enterprisedb
Attachments:
add_spigettypmod.patchtext/x-diff; charset=US-ASCII; name=add_spigettypmod.patchDownload
diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c
index 81f284c..659122e 100644
--- a/src/backend/executor/spi.c
+++ b/src/backend/executor/spi.c
@@ -955,6 +955,24 @@ SPI_gettypeid(TupleDesc tupdesc, int fnumber)
return (SystemAttributeDefinition(fnumber, true))->atttypid;
}
+int4
+SPI_gettypemod(TupleDesc tupdesc, int fnumber)
+{
+ SPI_result = 0;
+
+ if (fnumber > tupdesc->natts || fnumber == 0 ||
+ fnumber <= FirstLowInvalidHeapAttributeNumber)
+ {
+ SPI_result = SPI_ERROR_NOATTRIBUTE;
+ return -1;
+ }
+
+ if (fnumber > 0)
+ return tupdesc->attrs[fnumber - 1]->atttypmod;
+ else
+ return (SystemAttributeDefinition(fnumber, true))->atttypmod;
+}
+
char *
SPI_getrelname(Relation rel)
{
diff --git a/src/include/executor/spi.h b/src/include/executor/spi.h
index cfbaa14..a358710 100644
--- a/src/include/executor/spi.h
+++ b/src/include/executor/spi.h
@@ -113,6 +113,7 @@ extern char *SPI_getvalue(HeapTuple tuple, TupleDesc tupdesc, int fnumber);
extern Datum SPI_getbinval(HeapTuple tuple, TupleDesc tupdesc, int fnumber, bool *isnull);
extern char *SPI_gettype(TupleDesc tupdesc, int fnumber);
extern Oid SPI_gettypeid(TupleDesc tupdesc, int fnumber);
+extern int4 SPI_gettypemod(TupleDesc tupdesc, int fnumber);
extern char *SPI_getrelname(Relation rel);
extern char *SPI_getnspname(Relation rel);
extern void *SPI_palloc(Size size);
On Wed, Feb 1, 2012 at 5:23 AM, Chetan Suttraway
<chetan.suttraway@enterprisedb.com> wrote:
Hi All,
This is regarding the TODO item :
"Add SPI_gettypmod() to return a field's typemod from a TupleDesc"The related message is:
http://archives.postgresql.org/pgsql-hackers/2005-11/msg00250.phpThis basically talks about having an SPI_gettypemod() which returns the
typmod of a field of tupdescPlease refer the attached patch based on the suggested implementation.
Please add this to the next CommitFest:
https://commitfest.postgresql.org/action/commitfest_view/open
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
On Thu, Feb 2, 2012 at 8:11 PM, Robert Haas <robertmhaas@gmail.com> wrote:
On Wed, Feb 1, 2012 at 5:23 AM, Chetan Suttraway
<chetan.suttraway@enterprisedb.com> wrote:Hi All,
This is regarding the TODO item :
"Add SPI_gettypmod() to return a field's typemod from a TupleDesc"The related message is:
http://archives.postgresql.org/pgsql-hackers/2005-11/msg00250.phpThis basically talks about having an SPI_gettypemod() which returns the
typmod of a field of tupdescPlease refer the attached patch based on the suggested implementation.
Please add this to the next CommitFest:
https://commitfest.postgresql.org/action/commitfest_view/open
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
At the given link, I am able to choose only "System administration" under
commitfest topic.
I think there has to be "server features" or "Miscellaneous".
Regards,
Chetan
--
EnterpriseDB Corporation
The Enterprise PostgreSQL Company
Website: www.enterprisedb.com
EnterpriseDB Blog : http://blogs.enterprisedb.com
Follow us on Twitter : http://www.twitter.com/enterprisedb
Chetan Suttraway wrote:
Robert Haas wrote:
Please add this to the next CommitFest:
https://commitfest.postgresql.org/action/commitfest_view/open
At the given link, I am able to choose only "System administration"
under commitfest topic.
I think there has to be "server features" or "Miscellaneous".
I created all the topics from the last CF, in the same order, and
moved this to "Replication and Recovery" -- it is about the ability
to recover if the OS crashes around the time initdb completes, right?
-Kevin
Import Notes
Resolved by subject fallback
"Kevin Grittner" wrote:
moved this to "Replication and Recovery"
Oh, that was a different patch -- I didn't see yours.
(It's early, and the caffeine isn't working yet.)
Anyway, you should have plenty of options now.
-Kevin
Import Notes
Resolved by subject fallback
On Tue, Feb 7, 2012 at 5:44 PM, Kevin Grittner
<Kevin.Grittner@wicourts.gov>wrote:
"Kevin Grittner" wrote:
moved this to "Replication and Recovery"
Oh, that was a different patch -- I didn't see yours.
(It's early, and the caffeine isn't working yet.)
Anyway, you should have plenty of options now.
-Kevin
Thanks Kevin :)
--
EnterpriseDB Corporation
The Enterprise PostgreSQL Company
Website: www.enterprisedb.com
EnterpriseDB Blog : http://blogs.enterprisedb.com
Follow us on Twitter : http://www.twitter.com/enterprisedb
On ons, 2012-02-01 at 15:53 +0530, Chetan Suttraway wrote:
This is regarding the TODO item :
"Add SPI_gettypmod() to return a field's typemod from a TupleDesc"
My first thought was, this should be spelled SPI_gettypmod(). Not sure
what others think.
On Tue, Feb 7, 2012 at 4:25 PM, Peter Eisentraut <peter_e@gmx.net> wrote:
On ons, 2012-02-01 at 15:53 +0530, Chetan Suttraway wrote:
This is regarding the TODO item :
"Add SPI_gettypmod() to return a field's typemod from a TupleDesc"My first thought was, this should be spelled SPI_gettypmod(). Not sure
what others think.
+1.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
On Wed, Feb 8, 2012 at 8:15 AM, Robert Haas <robertmhaas@gmail.com> wrote:
On Tue, Feb 7, 2012 at 4:25 PM, Peter Eisentraut <peter_e@gmx.net> wrote:
On ons, 2012-02-01 at 15:53 +0530, Chetan Suttraway wrote:
This is regarding the TODO item :
"Add SPI_gettypmod() to return a field's typemod from a TupleDesc"My first thought was, this should be spelled SPI_gettypmod(). Not sure
what others think.+1.
The reason for using SPI_gettypemod() name was that I did see
SPI_gettypeid().
Anyways, will update patch with recommended name.
Regards,
Chetan
--
EnterpriseDB Corporation
The Enterprise PostgreSQL Company
Website: www.enterprisedb.com
EnterpriseDB Blog : http://blogs.enterprisedb.com
Follow us on Twitter : http://www.twitter.com/enterprisedb
On Wed, Feb 8, 2012 at 12:19 PM, Chetan Suttraway <
chetan.suttraway@enterprisedb.com> wrote:
On Wed, Feb 8, 2012 at 8:15 AM, Robert Haas <robertmhaas@gmail.com> wrote:
On Tue, Feb 7, 2012 at 4:25 PM, Peter Eisentraut <peter_e@gmx.net> wrote:
On ons, 2012-02-01 at 15:53 +0530, Chetan Suttraway wrote:
This is regarding the TODO item :
"Add SPI_gettypmod() to return a field's typemod from a TupleDesc"My first thought was, this should be spelled SPI_gettypmod(). Not sure
what others think.+1.
The reason for using SPI_gettypemod() name was that I did see
SPI_gettypeid().Anyways, will update patch with recommended name.
Regards,
Chetan
Please refer the attached patch which now uses SPI_gettypmod() name.
Regards,
Chetan
--
EnterpriseDB Corporation
The Enterprise PostgreSQL Company
Website: www.enterprisedb.com
EnterpriseDB Blog : http://blogs.enterprisedb.com
Follow us on Twitter : http://www.twitter.com/enterprisedb
Attachments:
add_spigettypmod.1.patchtext/x-diff; charset=US-ASCII; name=add_spigettypmod.1.patchDownload
diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c
index 81f284c..1f4632e 100644
--- a/src/backend/executor/spi.c
+++ b/src/backend/executor/spi.c
@@ -955,6 +955,24 @@ SPI_gettypeid(TupleDesc tupdesc, int fnumber)
return (SystemAttributeDefinition(fnumber, true))->atttypid;
}
+int4
+SPI_gettypmod(TupleDesc tupdesc, int fnumber)
+{
+ SPI_result = 0;
+
+ if (fnumber > tupdesc->natts || fnumber == 0 ||
+ fnumber <= FirstLowInvalidHeapAttributeNumber)
+ {
+ SPI_result = SPI_ERROR_NOATTRIBUTE;
+ return -1;
+ }
+
+ if (fnumber > 0)
+ return tupdesc->attrs[fnumber - 1]->atttypmod;
+ else
+ return (SystemAttributeDefinition(fnumber, true))->atttypmod;
+}
+
char *
SPI_getrelname(Relation rel)
{
diff --git a/src/include/executor/spi.h b/src/include/executor/spi.h
index cfbaa14..dedb1c7 100644
--- a/src/include/executor/spi.h
+++ b/src/include/executor/spi.h
@@ -113,6 +113,7 @@ extern char *SPI_getvalue(HeapTuple tuple, TupleDesc tupdesc, int fnumber);
extern Datum SPI_getbinval(HeapTuple tuple, TupleDesc tupdesc, int fnumber, bool *isnull);
extern char *SPI_gettype(TupleDesc tupdesc, int fnumber);
extern Oid SPI_gettypeid(TupleDesc tupdesc, int fnumber);
+extern int4 SPI_gettypmod(TupleDesc tupdesc, int fnumber);
extern char *SPI_getrelname(Relation rel);
extern char *SPI_getnspname(Relation rel);
extern void *SPI_palloc(Size size);