postgresql-9.2

What is the best way to replace a string with another string on entire table?

空扰寡人 提交于 2019-12-11 14:58:37
问题 My question is similar to below but I want to replace it for any column: postgresql - replace all instances of a string within text field for instance - replace all instances of cat with dog in entire table(all rows) I am expecting something like below query to work for all columns(without specifying the column name in update query). UPDATE table_name SET information_schema.columns replace (information_schema.columns, 'old_value', 'new_value'); which actually doesn't seems to work. Any

(var)char as the type of the column for performance?

不问归期 提交于 2019-12-11 11:08:07
问题 I have a column called "status" in PostgreSQL. First it used to be "status_id" of type integer . The values were kept on client, so there was no table on the server called statuses where I'd keep those statuses and then do inner join with the first table. I used to send the ids of the statuses from the client (they had the names on the client). However, at some point I understood I'd better make the server hold those statuses. Not in a separate table but in the first one and I want to make

Create 10 different random numbers

走远了吗. 提交于 2019-12-11 10:09:55
问题 I want generate some random data. ~50k rows Every row have ID autonumeric and 10 numeric values from 1 to 90. +----+------+------+------+------+------+------+------+------+------+------+ | id | nr1 | nr2 | nr3 | nr4 | nr5 | nr6 | nr7 | nr8 | nr9 | nr10 | +----+------+------+------+------+------+------+------+------+------+------+ | 1 | 1 | 39 | 19 | 23 | 28 | 80 | 3 | 42 | 60 | 32 | +----+------+------+------+------+------+------+------+------+------+------+ | 2 | 43 | 18 | 3 | 24 | 29 | 33 |

Postgres deadlock

梦想与她 提交于 2019-12-11 08:59:51
问题 I am seeing some unexplained deadlocks in our Postgres database. Simplifying the related queries, one of the transactions involved in the deadlock is: BEGIN; UPDATE A SET CHUNK_ID=1, STATUS='PROCESSING' WHERE ID IN ( SELECT ID FROM A WHERE CHUNK_ID IS NULL ORDER BY O_ID LIMIT 1000 FOR UPDATE ); COMMIT; and the other one is: BEGIN; UPDATE A SET STATUS='SENT' WHERE ID = 1; UPDATE A SET STATUS='SENT' WHERE ID = 2; UPDATE A SET STATUS='SENT' WHERE ID = 3; ... COMMIT; My question is how is it

handling rails + postgres and timezones

限于喜欢 提交于 2019-12-11 05:59:25
问题 I have an application which uses many different timezones... it sets them in a controller and they change depending on the user. All the times are stored in UTC without a timestamp etc. My understanding is this is the normal way for Rails to handle timezones. This works fine 99% of the time until i need to do something directly with Postgres then the Timezone becomes a problem. For example this query is completely wrong except for GMT, for example in Central Time Zone, depending on the hour

Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException

对着背影说爱祢 提交于 2019-12-11 05:22:18
问题 I configured hibernate to use Posgresql <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQL92Dialect</property> <property name="hibernate.connection.driver_class">org.postgresql.Driver</property> But I get exception when I start tomcat: 23-Jul-2017 21:22:25.544 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 7529 ms 23-Jul-2017 21:26:47.901 INFO [http-nio-8081-exec-9] org.hibernate.Version.logVersion HHH000412: Hibernate Core {5.2.10.Final} 23-Jul-2017

SQL postgres aggregation/pivot of data by weeks with totals

孤者浪人 提交于 2019-12-11 04:39:20
问题 I have a table EventLogs which records a given Event's details such as the date of the event and the fee. +------+----------+---------------------------+-------------------+ | id | place_id | start_at | total_fee_pennies | +------+----------+---------------------------+-------------------+ | 4242 | 40 | 2013-10-20 19:00:00 +0100 | 8700 | | 4288 | 48 | 2013-10-22 20:00:00 +0100 | 8000 | | 4228 | 141 | 2013-10-17 19:30:00 +0100 | 20000 | | 4232 | 19 | 2013-10-20 19:30:00 +0100 | 8000 | | 4239 |

SQLAlchemy get output parameters from a postgresql stored procedure

可紊 提交于 2019-12-11 03:57:21
问题 I am using Postgresql9.2 and SQLAlchemy0.8 . I have a stored procedure in database which has many out parameters and i want them to use by dot notation. But so far I have failed miserably. Below is how my code looks like. An example to show what i am doing is as follows. CREATE OR REPLACE FUNCTION stored_proc_name(IN in_user_id bigint, IN in_amount bigint, OUT pout_one bigint, OUT pout_two bigint ) RETURNS record AS $BODY$ begin select count(*) as AliasOne into pout_one from tabe_names where

Allow only work time in reservations table

此生再无相见时 提交于 2019-12-11 03:47:25
问题 PostgreSql 9.2 Reservation table is defined as CREATE EXTENSION btree_gist; CREATE TABLE schedule ( id serial primary key, during tsrange not null, EXCLUDE USING gist (during WITH &&) ); Holidays are listed in table CREATE TABLE holiday ( day primary key ); Work hours are from 8 to 18:00 in work days and reservatons can be done by 30 minute intervals only. How to add constraints to during values so that it allows only reservations during work time: Start and end dates in tsrange are always

Subselect on array_agg in postgresql

霸气de小男生 提交于 2019-12-11 03:47:11
问题 Is there a way to use a value from an aggregate function in a having clause in Postgresql 9.2+? For example, I would like to get each monkey_id with a 2nd highest number > 123, as well as the second highest number. In the example below, I'd like to get (monkey_id 1, number 222). monkey_id | number ------------------ 1 | 222 1 | 333 2 | 0 2 | 444 SELECT monkey_id, (array_agg(number ORDER BY number desc))[2] as second FROM monkey_numbers GROUP BY monkey_id HAVING second > 123 I get column