postgresql-9.3

Trigger with dynamic field name

可紊 提交于 2019-12-19 07:41:51
问题 I have a problem on creating PostgreSQL (9.3) trigger on update table. I want set new values in the loop as EXECUTE 'NEW.'|| fieldName || ':=''some prepend data'' || NEW.' || fieldName || ';'; where fieldName is set dynamically. But this string raise error ERROR: syntax error at or near "NEW" How do I go about achieving that? 回答1: You can implement that rather conveniently with the hstore operator #= : Make sure the additional module is installed properly ( once per database), in a schema

Trigger with dynamic field name

♀尐吖头ヾ 提交于 2019-12-19 07:41:08
问题 I have a problem on creating PostgreSQL (9.3) trigger on update table. I want set new values in the loop as EXECUTE 'NEW.'|| fieldName || ':=''some prepend data'' || NEW.' || fieldName || ';'; where fieldName is set dynamically. But this string raise error ERROR: syntax error at or near "NEW" How do I go about achieving that? 回答1: You can implement that rather conveniently with the hstore operator #= : Make sure the additional module is installed properly ( once per database), in a schema

refresh materialized view periodically postgres

自作多情 提交于 2019-12-19 05:51:11
问题 for optimization purposes I'm using a materialized view, to refresh it periodically I have set a cron job that runs each period t in my case every three hours. my questions are: what's the best way to refresh a materialized view? what can go wrong if using a cron job to refresh a materialized view? I have come across a postgres plugin that schedule jobs link 回答1: the best way is to execute periodically a script that does the task: the script is: #!/bin/sh psql -U user_name -d database

Refresh materialized views: Concurrency, transactional behaviour

谁说我不能喝 提交于 2019-12-19 05:34:35
问题 The official PostgreSQL 9.3 documentation on REFRESH MATERIALIZED VIEW does not yet describe it in detail. A quote from this blog: materialized views in Postgres 9.3 have a severe limitation consisting in using an exclusive lock when refreshing it. This basically blocks any attempts to read a materialized view while it is being refreshed with new data from its parent relations Another quote from a posting in the mailing list: if I understand things correctly REFRESH MATERIALIZED VIEW locks

Cluster and Non cluster index in PostgreSQL

感情迁移 提交于 2019-12-18 17:24:51
问题 I'm using PostgreSQL 9.3 version to create database. I have the following table test with some columns list. create table test ( cola varchar(10), colb varchar(10), colc varchar(10), cold varchar(10) ); Now I want to create a indexs on some columns. For example: I want to create clustered index for columns cola and colb . And I want to create non clustered index for columns colc and cold . As I referred this And this ,I come to know that there is no clustered and non clustered index in

Preserve timezone in PostgreSQL timestamptz type

那年仲夏 提交于 2019-12-18 11:48:26
问题 For an ISO8601 compliant datetime 2004-10-19 10:23:54+02 Is it possible to have that value, with +02 offset, reflected in the stored column value and also preserved when it is selected? From my reading of the appropriate section of the docs Postgres' default behavior is to convert to UTC at which point the original offset is lost. This is certainly what I'm seeing. The data is accessed via an ORM that is not able to add any special tz conversion so I really need to simply store the datetime

Calculating the Weighted Average Cost of products stock

那年仲夏 提交于 2019-12-18 11:36:56
问题 I have to calculate my products stock cost, so for every product after each buy, i have to recalculate the Weighted Average Cost . I got a view thats bring me the current product's stock after each in/out: document_type document_date product_id qty_out qty_in price row_num stock_balance SI 01/01/2014 52 0 600 1037.28 1 600 SI 01/01/2014 53 0 300 1357.38 2 300 LC 03/02/2014 53 100 0 1354.16 3 200 LC 03/02/2014 53 150 0 1355.25 4 50 LC 03/02/2014 52 100 0 1035.26 5 500 LC 03/02/2014 52 200 0

Creating a trigger for child table insertion returns confusing error

[亡魂溺海] 提交于 2019-12-18 07:06:40
问题 I am trying to write a trigger function that will input values into separate child tables, however I am getting an error I have not seen before. Here is an example set up: -- create initial table CREATE TABLE public.testlog( id serial not null, col1 integer, col2 integer, col3 integer, name text ); -- create child table CREATE TABLE public.testlog_a (primary key(id)) INHERITS(public.testlog); -- make trigger function for insert CREATE OR REPLACE FUNCTION public.test_log() RETURNS trigger AS $

Django Query sort case-insensitive using Model method with PostgreSQL

扶醉桌前 提交于 2019-12-18 06:51:42
问题 I'm really new to django, python and postgres... I can't seem to find the answer on how to order_by being case insensitive while using Model as the query method, only if you use direct SQL queries. Model @classmethod def get_channel_list(cls, account): return cls.objects.filter(accountid=account).order_by('-name').values_list('name', 'channelid') Data set and order it's currently being ordered in test b test a test channel a test channel a test 2 a b test Test Channel Test 3 Test 3 Test 2

Unable to connect to Postgres via PHP but can connect from command line and PgAdmin on different machine

若如初见. 提交于 2019-12-18 05:10:13
问题 I've had a quick search around (about 30 minutes) and tried a few bits, but nothing seems to work. Also please note I'm no Linux expert (I can do most basic stuff, simple installs, configurations etc) so some of the config I have may be obviously wrong, but I just don't see it! (feel free to correct any of the configs below) The Setup I have a running instance of PostgreSQL 9.3 on a Red Hat Enterprise Linux Server release 7.1 (Maipo) box. It's also running SELinux and IPTables. IPTables