postgresql-9.3

Refresh a materialized view automatically using a rule or notify

流过昼夜 提交于 2019-11-26 07:19:18
问题 I have a materialized view on a PostgreSQL 9.3 database which seldom changes (about twice a day). But when it does, I\'d like to update its data promptly. Here is what I was thinking about so far: There is a materialized view mat_view which gets its data from tables table1 and table2 using some join statement. Whenever something in table1 or table2 changes, I already have a trigger wich updates a little configuration table config consisting of table_name | mat_view_name | need_update --------

Is there a way to disable function overloading in Postgres

心不动则不痛 提交于 2019-11-26 06:47:29
问题 My users and I do not use function overloading in PL/pgSQL. We always have one function per (schema, name) tuple. As such, we\'d like to drop a function by name only, change its signature without having to drop it first, etc. Consider for example, the following function: CREATE OR REPLACE FUNCTION myfunc(day_number SMALLINT) RETURNS TABLE(a INT) AS $BODY$ BEGIN RETURN QUERY (SELECT 1 AS a); END; $BODY$ LANGUAGE plpgsql; To save time, we would like to invoke it as follows, without qualifying 1

Split given string and prepare case statement

旧城冷巷雨未停 提交于 2019-11-26 06:08:44
问题 Table : table_name create table table_name ( given_dates timestamp, set_name varchar ); Insertion of records : insert into table_name values(\'2001-01-01\'),(\'2001-01-05\'),(\'2001-01-10\'), (\'2001-01-15\'),(\'2001-01-20\'),(\'2001-01-25\'), (\'2001-02-01\'),(\'2001-02-05\'),(\'2001-02-10\'), (\'2001-02-15\'); Now I want to update set_name for some dates. For example : I want to update table like this: given_dates set_name ---------------------- 2001-01-01 s1 2001-01-05 s1 2001-01-10 s2

How to convert primary key from integer to serial?

笑着哭i 提交于 2019-11-26 03:45:38
问题 In a Postgres 9.3 table I have an integer as primary key with automatic sequence to increment, but I have reached the maximum for integer . How to convert it from integer to serial ? I tried: ALTER TABLE my_table ALTER COLUMN id SET DATA TYPE bigint; But the same does not work with the data type serial instead of bigint . Seems like I cannot convert to serial ? 回答1: serial is a pseudo data type, not an actual data type. It's an integer underneath with some additional DDL commands executed

How do I modify fields inside the new PostgreSQL JSON datatype?

做~自己de王妃 提交于 2019-11-26 01:29:12
问题 With postgresql 9.3 I can SELECT specific fields of a JSON data type, but how do you modify them using UPDATE? I can\'t find any examples of this in the postgresql documentation, or anywhere online. I have tried the obvious: postgres=# create table test (data json); CREATE TABLE postgres=# insert into test (data) values (\'{\"a\":1,\"b\":2}\'); INSERT 0 1 postgres=# select data->\'a\' from test where data->>\'b\' = \'2\'; ?column? ---------- 1 (1 row) postgres=# update test set data->\'a\' =

How do I query using fields inside the new PostgreSQL JSON datatype?

霸气de小男生 提交于 2019-11-25 23:30:15
问题 I am looking for some docs and/or examples for the new JSON functions in PostgreSQL 9.2. Specifically, given a series of JSON records: [ {name: \"Toby\", occupation: \"Software Engineer\"}, {name: \"Zaphod\", occupation: \"Galactic President\"} ] How would I write the SQL to find a record by name? In vanilla SQL: SELECT * from json_data WHERE \"name\" = \"Toby\" The official dev manual is quite sparse: http://www.postgresql.org/docs/devel/static/datatype-json.html http://www.postgresql.org