如何为Postgres应用程序组织参数 [英] How to organize parameters for a postgres application

查看:73
本文介绍了如何为Postgres应用程序组织参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究postgres应用程序.目前,我不确定如何最好地管理应用程序常量参数.例如,我想定义一个阈值变量,该变量将在多个函数中使用.

I am working on a postgres application. For the moment I am not sure how to manage application constant parameters best. For example I want to define a threshold variable which I am going to use in several functions.

一个想法是制作一个表"config",并在每次需要它们时查询该变量.对于快捷方式,将sql查询包装到其他函数中,即:t:= get_Config('Threshold');

One idea is making a table "config" and query the variable every time I need them. And for a shortcut wrap the sql query into an other function i.e.: t := get_Config('Threshold');

但是实际上我对此并不很幸运.处理自定义应用程序配置参数的最佳方法是什么?它们在维护方面应该很方便,我想避免每次都查询常量.例如,在oracle中,您可以将常量编译为程序包规范.有没有更好的方法来处理此类配置参数?

But in fact I am not really lucky with this. What is the best way to handle custom application configuration parameters? They should be handy in maintainance and I want to avoid querying every time for constants. In oracle for example you could compile constants into package specs. Are there any better ways to deal with such configuration parameters?

推荐答案

几年来,我一直按照您描述全局参数的方式来组织全局参数.似乎有点尴尬,但效果很好.

I have organized global parameters just the way you describe it for some years now. It seems a bit awkward but it works just fine.

我有很多这样的东西,所以我在配置表中添加了一个整数加索引,并使用get_config($my_id)(加注释)-速度稍快,但可读性较低.

I have got quite a number of those, so I added an integer plus index to my config table and use get_config($my_id) (plus comment) - which is slightly faster but less readable.

,您可以使用custom_variable_classes. 请参阅:如何在PostgreSQL中声明变量

OR you can use custom_variable_classes. See: how to declare variable in PostgreSQL

这篇关于如何为Postgres应用程序组织参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆