English 中文(简体)
PL/pgSQL - %TYPE和ARRAY
原标题:PL/pgSQL - %TYPE and ARRAY

Is it possible to use the %TYPE and array together?

CREATE FUNCTION role_update(
  IN id "role".role_id % TYPE,
  IN name   "role".role_name % TYPE,
  IN user_id_list "user".user_id % TYPE[],
  IN permission_id_list  INT[]
)

我只字眼错了,但我不想重复任何一栏,因此我想使用<条码>“用户”_id % TYPE,而不是单纯的<条码>INT<>,因为随后便更容易修改任何一栏。

最佳回答

The manual:

The type of a column is referenced by writing table_name.column_name%TYPE. Using this feature can sometimes help make a function independent of changes to the definition of a table.

The same functionality can be used in the RETURNS clause.

但是,从一个参考栏中得出一个阵列,至少我不知道什么是哪一个。

About modifying any column type later:
You are aware that this type of syntax is only a syntactical convenience to derive the type from a table column? Once created, there is no link whatsoever to the table or column involved.

It helps to keep a whole create script in sync. But id doesn t help with later changes to live objects in the database.

Related answer on dba.SE:

问题回答

在功能参数中采用参考型号是毫无意义的(在PogreSQL中),因为它在中间转化为实际类型,并储存为实际类型。 Sorry, PostgreSQL并不支持这一功能——在职能范围内使用参考型号的情况有所不同,而实际类型在届会期间首次发现。





相关问题
摘录数据

我如何将Excel板的数据输入我的Django应用? I m将PosgreSQL数据库作为数据库。

Postgres dump of only parts of tables for a dev snapshot

On production our database is a few hundred gigabytes in size. For development and testing, we need to create snapshots of this database that are functionally equivalent, but which are only 10 or 20 ...

How to join attributes in sql select statement?

I want to join few attributes in select statement as one for example select id, (name + + surname + + age) as info from users this doesn t work, how to do it? I m using postgreSQL.

What text encoding to use?

I need to setup my PostgreSQL DB s text encoding to handle non-American English characters that you d find showing up in languages such as German, Spanish, and French. What character encoding should ...

SQL LIKE condition to check for integer?

I am using a set of SQL LIKE conditions to go through the alphabet and list all items beginning with the appropriate letter, e.g. to get all books where the title starts with the letter "A": SELECT * ...

热门标签