postgresql-9.4

PostgreSQL Trigger creation issues

﹥>﹥吖頭↗ 提交于 2019-12-24 14:47:31
问题 I've looked all over the web and stackoverflow and despite trying to do everything I see I can't get this to work. Code: CREATE TABLE "ExpressionHistory" ( ExpressionHistoryId SERIAL PRIMARY KEY, ExpressionId INT NOT NULL, UserId INT NOT NULL, AccessDate TIMESTAMP NOT NULL, CreatedBy VARCHAR(12) NOT NULL, CreatedDate TIMESTAMP NOT NULL, ModifiedBy VARCHAR(12) NOT NULL, ModifiedDate TIMESTAMP NOT NULL); ALTER TABLE "ExpressionHistory" ADD CONSTRAINT FK_EXPRESSIONHISTORY_EXPRESSION FOREIGN KEY

how to apply split_part function from end of string in postgres

雨燕双飞 提交于 2019-12-24 12:19:12
问题 I want to split the below string (present in a single column) separated by spaces from the end. For the below 3 rows, I want the following output OUTPUT: Country STATE STREET UNIT AU NSW 2 12 AU NSW 51 AU NSW 12 INPUT: 12 2 NOELA PLACE ST MARYS NSW 2760 AU 51 MALABAR ROAD SOUTH COOGEE NSW 2034 AU 12 LISTER STREET WINSTON HILLS NSW 2153 AU 回答1: of course such conditional parsing is not reliable: t=# with v(a) as( values('12 2 NOELA PLACE ST MARYS NSW 2760 AU') ,('51 MALABAR ROAD SOUTH COOGEE

Change PostgreSQL date language from request

谁说胖子不能爱 提交于 2019-12-24 04:40:50
问题 I'm kind of new to PostgreSQL and I'm trying to change the locale of the date function results, to get the result of to_char(my_date, 'Month') in another language. Here are some of my settings : $> show lc_time; en_US.UTF-8 I found in the documentation that the locale could be changed at the database initialization : initdb --locale=fr_FR But that's not exactly what I'm looking for. In MySQL, I used to do it like : SET lc_time_names = 'fr_FR'; But unfortunately, I can't find a way to do it

What is the second argument in array_length() function?

不打扰是莪最后的温柔 提交于 2019-12-23 07:48:52
问题 Postgresql 9.4 has functions for array. One of them is array_length(anyarray, int) . It get two argumetns. What is the second argument? In all examples it has value 1 . But nowhere says what it is. 回答1: That's array's dimension . Consider an example with a 2D array 3×2: array_length(array[[1, 2], [3, 4], [5, 6]], 1) ---> 3 array_length(array[[1, 2], [3, 4], [5, 6]], 2) ---> 2 The size of the first dimension is 3; the size of the second dimension is 2. 来源: https://stackoverflow.com/questions

How do you create a Postgresql JSONB array in array index?

帅比萌擦擦* 提交于 2019-12-22 12:32:39
问题 I have structure like this: user_id, a. a is of type jsonb and has the following structure: { b: [ {ids: [1,2,3,4]}, {ids: [2,3,4]}, {ids: [1,2,4]}, ... ] } How would I make an index that enabled me to find all users (user_id) that has a certain id in the ids list? 回答1: Is a GIN index what you want? It seems that you first need to organized the IDs into a form that is more tractable. I'm more familiar with Python than I am with the PostgreSQL ways of manipulating JSON, so I used PL/Python for

How do you create a Postgresql JSONB array in array index?

谁都会走 提交于 2019-12-22 12:32:15
问题 I have structure like this: user_id, a. a is of type jsonb and has the following structure: { b: [ {ids: [1,2,3,4]}, {ids: [2,3,4]}, {ids: [1,2,4]}, ... ] } How would I make an index that enabled me to find all users (user_id) that has a certain id in the ids list? 回答1: Is a GIN index what you want? It seems that you first need to organized the IDs into a form that is more tractable. I'm more familiar with Python than I am with the PostgreSQL ways of manipulating JSON, so I used PL/Python for

How do you create a Postgresql JSONB array in array index?

时光总嘲笑我的痴心妄想 提交于 2019-12-22 12:32:02
问题 I have structure like this: user_id, a. a is of type jsonb and has the following structure: { b: [ {ids: [1,2,3,4]}, {ids: [2,3,4]}, {ids: [1,2,4]}, ... ] } How would I make an index that enabled me to find all users (user_id) that has a certain id in the ids list? 回答1: Is a GIN index what you want? It seems that you first need to organized the IDs into a form that is more tractable. I'm more familiar with Python than I am with the PostgreSQL ways of manipulating JSON, so I used PL/Python for

Operator does not exist: json = json

久未见 提交于 2019-12-21 06:56:20
问题 when I try to select some record from a table SELECT * FROM movie_test WHERE tags = ('["dramatic","women", "political"]'::json) The sql code cast a error LINE 1: SELECT * FROM movie_test WHERE tags = ('["dramatic","women",... ^ HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. ********** 错误 ********** ERROR: operator does not exist: json = json SQL 状态: 42883 指导建议:No operator matches the given name and argument type(s). You might need to

Revoke access to postgres database for a role

自作多情 提交于 2019-12-21 05:03:49
问题 I have created a separate role "newrole" and new schema "newschema" for a certain user that should only execute some stored functions. I have managed to revoke access to schema "public" for the current database. Logged in as "newrole" I still have access to postgres database like this: SELECT * FROM pg_user I want to revoke all access to the postgres database and tried following that not work: REVOKE ALL ON DATABASE postgres FROM newrole When logged in as newrole I can still read the postgres

Combine two JSON objects in PostgreSQL

大城市里の小女人 提交于 2019-12-21 02:23:33
问题 I have two JSON rows in a PostgreSQL 9.4 table: the_column ---------------------- {"evens": [2, 4, 6]} {"odds": [1, 3, 5]} I want to combine all of the rows into one JSON object. (It should work for any number of rows.) Desired output: {"evens": [2, 4, 6], "odds": [1, 3, 5]} 回答1: Use json_agg() to get an array: SELECT json_agg(source_column) AS the_column FROM tbl; Or json_each() in a LATERAL join and json_object_agg() to assemble elements: SELECT json_object_agg(key, value) AS the_column