How to organize parameters for a postgres application

风流意气都作罢 提交于 2019-12-25 03:28:15

问题


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.

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');

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?


回答1:


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.

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.

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



来源:https://stackoverflow.com/questions/7406137/how-to-organize-parameters-for-a-postgres-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!