Questions tagged «composite-types»


2
复合主键效率作为外键
我有一个带有复合主键(由4列组成)的表,该键用于确保没有重复项输入到表中。我现在需要一个新表,该表需要将该表中的键作为外键引用。 我的问题是哪种方法对查找速度更有效: 1)我是否创建包括所有4列的新表,并在外键中引用它们。 要么 2)我是否在主键表中创建了一个新的标识列,并将其用作新表中的外键。 预计该数据库将存储大量数据,因此到目前为止,我已经建立了该数据库,以最大程度地减少每个表中存储的数据量。考虑到这一点,选项2将是最好的方法,因为我将为每行保存2个int列和一个datetime列,但是我想避免不必要的增加查找时间。

1
仅给出字段名称,如何访问NEW或OLD字段?
我正在写一个验证触发器。触发器必须验证数组的总和等于另一个字段。由于我有很多这种验证的实例,因此我想编写一个过程并创建多个触发器,每个触发器都有一组不同的要检查的字段。 例如,我具有以下架构: CREATE TABLE daily_reports( start_on date , show_id uuid , primary key(start_on, show_id) -- _graph are hourly values, while _count is total for the report , impressions_count bigint not null , impressions_graph bigint[] not null -- interactions_count, interactions_graph -- twitter_interactions_count, twitter_interactions_graph ); 验证必须确认impressions_count = sum(impressions_graph)。 我被卡住是因为我不知道如何NEW从plpgsql中动态访问字段: CREATE FUNCTION validate_sum_of_array_equals_other() …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.