How to explicitly refer to columns of composite type in Postgre?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
12 views
There is a composite type:
CREATE TYPE t_well AS ( id INTEGER, name VARCHAR(10), altitude NUMERIC(10,3), x NUMERIC(10,6), y NUMERIC(10,6) );


When using this type of the queries must strictly follow the order of the columns in the definition. If I try to pass a variable of that type in the function:
SELECT * FROM p_well_operations_new(1, ROW(1, 'bla', 42, 1.99, 3.45));

you cannot change the order of columns, otherwise the value will be written incorrectly.

How to explicitly specify the columns in the composite type? Is this even possible?

Something like this for example:
SELECT * FROM p_well_operations_new(1, ROW(id=1, name='bla',...));
by | 12 views

2 Answers

0 like 0 dislike
In the sample, fields of values of complex types are also possible such syntax incidents. For example, to select one field from the result of a function that returns a composite value, you need to write something like this:

SELECT (my_func(...)).field FROM ...
No extra brackets in the query will occur a syntax error.

Although you have some other issue... Read docks.
by
0 like 0 dislike
In the documentation, nothing useful found
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
35,573 users