英文:
How to find out the array dimensions of functions in postgres?
问题
I'll only translate the code part for you:
我可以从information_schema.parameters
(或pg_proc
)中找到有关参数的信息,但是我无法找出如何找到数组参数的维度?
例如:
CREATE OR REPLACE FUNCTION pg_temp.one_dim(arr TEXT[]) RETURNS TEXT[]
LANGUAGE sql
AS $$
SELECT arr;
$$;
CREATE OR REPLACE FUNCTION pg_temp.two_dim(arr TEXT[][]) RETURNS TEXT[][]
LANGUAGE sql
AS $$
SELECT arr;
$$;
SELECT *
FROM information_schema.parameters p
WHERE p.parameter_name = 'arr';
返回:
"specific_catalog","specific_schema","specific_name","ordinal_position","parameter_mode","is_result","as_locator","parameter_name","data_type","character_maximum_length","character_octet_length","character_set_catalog","character_set_schema","character_set_name","collation_catalog","collation_schema","collation_name","numeric_precision","numeric_precision_radix","numeric_scale","datetime_precision","interval_type","interval_precision","udt_catalog","udt_schema","udt_name","scope_catalog","scope_schema","scope_name","maximum_cardinality","dtd_identifier","parameter_default"
"postgres","pg_temp_10","one_dim_119648",1,"IN","NO","NO","arr","ARRAY",NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,"postgres","pg_catalog","_text",NULL,NULL,NULL,NULL,"1",NULL
"postgres","pg_temp_10","two_dim_119649",1,"IN","NO","NO","arr","ARRAY",NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,"postgres","pg_catalog","_text",NULL,NULL,NULL,NULL,"1",NULL
英文:
I can find information about parameters from the information_schema.parameters
(or pg_proc
), but I can't work out how to find the dimensions of an array parameter?
For example:
CREATE OR REPLACE FUNCTION pg_temp.one_dim(arr TEXT[]) RETURNS TEXT[]
LANGUAGE sql
AS $$
SELECT arr;
$$;
CREATE OR REPLACE FUNCTION pg_temp.two_dim(arr TEXT[][]) RETURNS TEXT[][]
LANGUAGE sql
AS $$
SELECT arr;
$$;
SELECT *
FROM information_schema.parameters p
WHERE p.parameter_name = 'arr';
Returns:
"specific_catalog","specific_schema","specific_name","ordinal_position","parameter_mode","is_result","as_locator","parameter_name","data_type","character_maximum_length","character_octet_length","character_set_catalog","character_set_schema","character_set_name","collation_catalog","collation_schema","collation_name","numeric_precision","numeric_precision_radix","numeric_scale","datetime_precision","interval_type","interval_precision","udt_catalog","udt_schema","udt_name","scope_catalog","scope_schema","scope_name","maximum_cardinality","dtd_identifier","parameter_default"
"postgres","pg_temp_10","one_dim_119648",1,"IN","NO","NO","arr","ARRAY",NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,"postgres","pg_catalog","_text",NULL,NULL,NULL,NULL,"1",NULL
"postgres","pg_temp_10","two_dim_119649",1,"IN","NO","NO","arr","ARRAY",NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,"postgres","pg_catalog","_text",NULL,NULL,NULL,NULL,"1",NULL
答案1
得分: 1
你无法改变它。维度是值的一部分,而不是类型。PostgreSQL 数组是多维的。
=> 选择 pg_typeof(NULL::text[]);
┌───────────┐
│ pg_typeof │
├───────────┤
│ text[] │
└───────────┘
(1 行)
=> 选择 pg_typeof(NULL::text[][]);
┌───────────┐
│ pg_typeof │
├───────────┤
│ text[] │
└───────────┘
(1 行)
英文:
You can't. The dimensions are part of the value, not the type. PostgreSQL arrays are multi-dimensional.
=> SELECT pg_typeof(NULL::text[]);
┌───────────┐
│ pg_typeof │
├───────────┤
│ text[] │
└───────────┘
(1 row)
=> SELECT pg_typeof(NULL::text[][]);
┌───────────┐
│ pg_typeof │
├───────────┤
│ text[] │
└───────────┘
(1 row)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论