How do I get a table tuple and convert it to a Postgres array in C?


Avartiai

I am following the Postgres documentation https://www.postgresql.org/docs/8.2/xfunc-c.html to write a C function and create an extension (for hierarchical clustering) and I am confused.

  1. So I can do this by usingHeapTupleHeader t = PG_GETARG_HEAPTUPLEHEADER(0);
  2. How can I get the attribute value in that tuple? We have GET_ARGUMENT_BY_NUM, can I get a value for each column and put it into an array? (For some reason I want to get the data from the table, for example to cluster it).
  3. There is an example of using a specific table for a function (emp table). How can I use a random table for a function (I can't find an example)?
  4. Is c_overpaid(emp, limit)the emp table (in the documentation) called once, or as far as the row in the table is?
  5. For hierarchical clustering: Can I get table data from postgres, write it to a temp file, read that file, put it into an array, cluster it, and put the result into the database? (eg create or alter a table and partition it? eg: hub- is the whole table, part_1 is one cluster, part_2 is the second cluster and so on)
Lawrence Alber

You should read the current version of the documentation .

  1. Yes.

  2. As the example shows, with GetAttributeByName, but one more GetAttributeByNumfunction. I'm assuming you're talking about C arrays and not PostgreSQL arrays. If they have the same data type, you can populate the array with all the values.

  3. Then you will have to use special types record. For code samples, take a look at the function record_to_jsonand composite_to_jsonin src/backend/utils/adt/json.c.

  4. Because it appears in the SELECTlist , it is called for each line found .

  5. A little vague, but sure. I don't understand why you want to extract from the table. Why don't you write your own table access method , since you seem to want to define a new way of table storage.

    But be warned, it's definitely not ordinary, and it's best to get your feet wet with something ordinary first.

Related


How to convert array to tuple?

Niranjambaji I just want to convert an array to a tuple in Swift; something like this: >>> myArray = [1,2,3,4,5] >>> mytuple = tuple(myArray) >>> mytuple (1, 2, 3, 4, 5) What is the easiest way? (I just started learning Swift today, so I'm very, very new). ba

How do I get the min and max of a tuple

Jean Prosin How to get codes that return 2 (minimum) and 29 (maximum) intervals = [ (2, 18), (2, 15), (5, 28), (10, 14), (11, 29), (6, 17), (3, 7), (8, 22) ] z = max(intervals) print (z) Olivier Melançon When it comes time to

How can I convert the same tuple to an array at compile time?

death death I would like by pointing out that when I say homogenous tuples as the beginning, I mean that each element is of the same type, or that each element has a common member that is the same type across all elements. In this case, public members are also

How do I get the flat tuple type of a tuple?

Pedro A Consider I have a tuple of tuples: type Example = [[3,5,7], [4,9], [0,1,10,9]]; I want to create a utility Flatten<T>that Flatten<Example>results in: type FlatExample = Flatten<Example>; // type FlatExample = [3,5,7,4,9,0,1,10,9]; For my use case, yo

How to convert array to tuple?

Niranjambaji I just want to convert an array to a tuple in Swift; something like this: >>> myArray = [1,2,3,4,5] >>> mytuple = tuple(myArray) >>> mytuple (1, 2, 3, 4, 5) What is the easiest way? (I just started learning Swift today, so I'm very, very new). ba

(How) can I convert a table to a foreign table in Postgres?

Martin K We have a large table in a Postgres production database and we want to start "sharding" using external tables and inheritance. The required architecture would be to have 1 (empty) table (defining the schema) and several external tables that inherit fr

How do I get the min and max of a tuple

Jean Prosin How to get codes that return 2 (minimum) and 29 (maximum) intervals = [ (2, 18), (2, 15), (5, 28), (10, 14), (11, 29), (6, 17), (3, 7), (8, 22) ] z = max(intervals) print (z) Olivier Melançon When it comes time to

(How) can I convert a table to a foreign table in Postgres?

Martin K We have a large table in a Postgres production database and we want to start "sharding" using external tables and inheritance. The required architecture would be to have 1 (empty) table (defining the schema) and several external tables that inherit fr

How can I convert the same tuple to an array at compile time?

death death I would like by pointing out that when I say homogenous tuples as the beginning, I mean that each element is of the same type, or that each element has a common member that is the same type across all elements. In this case, public members are also

How do I get the flat tuple type of a tuple?

Pedro A Consider I have a tuple of tuples: type Example = [[3,5,7], [4,9], [0,1,10,9]]; I want to create a utility Flatten<T>that Flatten<Example>results in: type FlatExample = Flatten<Example>; // type FlatExample = [3,5,7,4,9,0,1,10,9]; For my use case, yo

how do i convert the array

Gimeaux I'm using a fax service and I want to merge the fax with multiple html url sources via a form. The script works with the following arrays: array(2) { [0]=> string(32) "https://www.test.net/test.pdf" [1]=> string(32) "https://www.test.net/test.pdf" } m

How do I get the min and max of a tuple

Jean Prosin How to get codes that return 2 (minimum) and 29 (maximum) intervals = [ (2, 18), (2, 15), (5, 28), (10, 14), (11, 29), (6, 17), (3, 7), (8, 22) ] z = max(intervals) print (z) Olivier Melançon When it comes time to

How to convert array to tuple?

Niranjambaji I just want to convert an array to a tuple in Swift; something like this: >>> myArray = [1,2,3,4,5] >>> mytuple = tuple(myArray) >>> mytuple (1, 2, 3, 4, 5) What is the easiest way? (I just started learning Swift today, so I'm very, very new). ba

how do I convert a double array in C to python list?

Karl Doenitz My C code: #include <stdio.h> #include <stdlib.h> #include <math.h> double * Make_A(){ double A[2]; A[0]=0.00001; double *p=(double *)&A; return p; } and there are my python code: from ctypes import * lib_cpp = cdll.LoadLibrary

how do i convert tuple to string

Narendra Petkar Using DataBaseLibrary for Robot Framework, I get a list of tuples @{recordList} Query select * from employee How to convert it to string? I want to write this to a file. When I try FOR ${ELEMENT} in @{recordList} str{$ELEMENT} If the va

How can I convert the same tuple to an array at compile time?

death death I would like by pointing out that when I say homogenous tuples as the beginning, I mean that each element is of the same type, or that each element has a common member that is the same type across all elements. In this case, public members are also

How do I get the flat tuple type of a tuple?

Pedro A Consider I have a tuple of tuples: type Example = [[3,5,7], [4,9], [0,1,10,9]]; I want to create a utility Flatten<T>that Flatten<Example>results in: type FlatExample = Flatten<Example>; // type FlatExample = [3,5,7,4,9,0,1,10,9]; For my use case, yo

How to convert array to tuple?

Niranjambaji I just want to convert an array to a tuple in Swift; something like this: >>> myArray = [1,2,3,4,5] >>> mytuple = tuple(myArray) >>> mytuple (1, 2, 3, 4, 5) What is the easiest way? (I just started learning Swift today, so I'm very, very new). ba

How do I get the flat tuple type of a tuple?

Pedro A Consider I have a tuple of tuples: type Example = [[3,5,7], [4,9], [0,1,10,9]]; I want to create a utility Flatten<T>that Flatten<Example>results in: type FlatExample = Flatten<Example>; // type FlatExample = [3,5,7,4,9,0,1,10,9]; For my use case, yo

How do I get the flat tuple type of a tuple?

Pedro A Consider I have a tuple of tuples: type Example = [[3,5,7], [4,9], [0,1,10,9]]; I want to create a utility Flatten<T>that Flatten<Example>results in: type FlatExample = Flatten<Example>; // type FlatExample = [3,5,7,4,9,0,1,10,9]; For my use case, yo

how do i convert the array

Gimeaux I'm using a fax service and I want to merge the fax with multiple html url sources via a form. The script works with the following arrays: array(2) { [0]=> string(32) "https://www.test.net/test.pdf" [1]=> string(32) "https://www.test.net/test.pdf" } m

how do i convert tuple to string

Narendra Petkar Using DataBaseLibrary for Robot Framework, I get a list of tuples @{recordList} Query select * from employee How to convert it to string? I want to write this to a file. When I try FOR ${ELEMENT} in @{recordList} str{$ELEMENT} If the va

How do I convert a list to a tuple within a tuple

Moore Cole enter: (('Alfred', ['gaming', 'shopping', 'sport', 'travel']), ('Carmen', ['cooking', 'pets', 'photography', 'shopping', 'sport',])) How can I convert this list to a tuple? Expected output: (('Alfred', ('gaming', 'shopping', 'sport', 'travel')),

How do I get the min and max of a tuple

Jean Prosin How to get codes that return 2 (minimum) and 29 (maximum) intervals = [ (2, 18), (2, 15), (5, 28), (10, 14), (11, 29), (6, 17), (3, 7), (8, 22) ] z = max(intervals) print (z) Olivier Melançon When it comes time to