postgresql-9.3

Heroku + Apartment PG::Error: ERROR: function pg_stat_statements_reset() does not exist

主宰稳场 提交于 2019-12-09 16:32:45
问题 I use Apartment gem in Rails 4 to support multi-tenancy in Postgres 9.3.3 on Heroku. An error is occurred when Apartment gem creates a new tenant. Deep investigation showed that a schema was created, but no tables inside. Heroku logs showed an error: PG::Error: ERROR: function pg_stat_statements_reset() does not exist 回答1: When a new schema is created Postgres is trying to reset stats by executing the function pg_stat_statements_reset() By default, this function can only be executed by

Add seconds into timestamp

只谈情不闲聊 提交于 2019-12-09 03:40:42
I want to add seconds into the given timestamp. Example : Given time: Declare t1 timestamp = '1900-01-01 02:00:00'; Now I want to add some 20 seconds into the given time. In SQL Server I have used DATEADD . But I searched and come to know that there is no such function provided by PostgreSQL. What will be the solution? Just add the 20 seconds: t1 := t1 + interval '20' second; The assignment operator in PL/pgSQL is := . The = is only there for backward compatibility. Don't use it. 来源: https://stackoverflow.com/questions/28672762/add-seconds-into-timestamp

High number of live/dead tuples in postgresql/ Vacuum not working

纵饮孤独 提交于 2019-12-09 02:30:06
问题 There is a table , which has 200 rows . But number of live tuples showing there is more than that (around 60K) . select count(*) from subscriber_offset_manager; count ------- 200 (1 row) SELECT schemaname,relname,n_live_tup,n_dead_tup FROM pg_stat_user_tables where relname='subscriber_offset_manager' ORDER BY n_dead_tup ; schemaname | relname | n_live_tup | n_dead_tup ------------+---------------------------+------------+------------ public | subscriber_offset_manager | 61453 | 5 (1 row) But

Dapper AddDynamicParams for IN query with IEnumerable parameter in Postgres

只谈情不闲聊 提交于 2019-12-08 22:02:41
问题 To start, I am having the same problem that was discussed, and allegedly fixed about two years ago. See the following question for that issue: Dapper AddDynamicParams for IN statement with "dynamic" parameter name The problem that I am experiencing is that when I perform a similar query ( SELECT * FROM MyTable WHERE MyId IN @myIds ) against my Postgres 9.3 database, I am getting the following exception: Npgsql.NpgsqlException : ERROR: 42883: operator does not exist: integer = integer[] My

Querying combinations of JSON returns odd results

ぃ、小莉子 提交于 2019-12-08 05:12:29
This is a followup to this question . I seem to have come across an edge case and I don't understand why I'm getting the wrong results. Using the data from the linked question, I can group them into combinations that use the same album, src, and background. For instance, using this data: CREATE TABLE reports (rep_id int primary key, data json); INSERT INTO reports (rep_id, data) VALUES (1, '{"objects":[{"album": 1, "src":"fooA.png", "pos": "top"}, {"album": 2, "src":"barB.png", "pos": "top"}], "background":"background.png"}'), (2, '{"objects":[{"album": 1, "src":"fooA.png", "pos": "top"}, {

unable to create postgis extension ERROR: could not access file “$libdir/postgis-2.0”: No such file or directory

微笑、不失礼 提交于 2019-12-08 04:26:42
问题 When I try run this command sudo -u postgres psql -h localhost -d template_postgis -f /Users/MyUser/postgis-2.0.6/postgis/postgis.sql I get this error SET BEGIN psql:/Users/MyUser/postgis-2.0.6/postgis/postgis.sql:49: ERROR: could not access file "$libdir/postgis-2.0": No such file or directory psql:/Users/MyUser/postgis-2.0.6/postgis/postgis.sql:54: ERROR: current transaction is aborted, commands ignored until end of transaction block . . . psql:/Users/MyUser/postgis-2.0.6/postgis/postgis

heroku pg: pull not fetching tables from heroku database

拟墨画扇 提交于 2019-12-08 04:24:28
问题 I'm trying to pull a heroku database to my local Windows computer by using heroku bash command heroku pg:pull HEROKU_POSTGRESQL_COLOR mydatabase --app appname , when I running above command I get the following error: 'env' is not recognized as an internal or external command, operable program or batch file.! But local database 'mydatabase' is created, but without any tables. My heroku app's database has a table in it, but it is not getting pulled to my local database. Help me to solve it. 回答1

PostgreSQL 9.3: Union two columns in one

让人想犯罪 __ 提交于 2019-12-08 04:16:04
问题 I want to show the given records in the following table into the specific format which is shown below in the table. Creating table: Test_1 CREATE TABLE Test_1 ( ColumnA varchar, ColumnB varchar ); Insertion of records: INSERT INTO Test_1 values('A101','B101'),('A102','B102'), ('A103','B103'),('A104','B104'), ('A105','B105'),('A106','B106'), ('A107','B107'),('A108','B108'), ('A109','B109'),('A201','B201'); I want to show the result like this: Expected Result : ColumnA ColumnX -----------------

Add seconds into timestamp

柔情痞子 提交于 2019-12-08 04:11:31
问题 I want to add seconds into the given timestamp. Example : Given time: Declare t1 timestamp = '1900-01-01 02:00:00'; Now I want to add some 20 seconds into the given time. In SQL Server I have used DATEADD . But I searched and come to know that there is no such function provided by PostgreSQL. What will be the solution? 回答1: Just add the 20 seconds: t1 := t1 + interval '20' second; The assignment operator in PL/pgSQL is := . The = is only there for backward compatibility. Don't use it. 来源:

Querying combinations of JSON returns odd results

偶尔善良 提交于 2019-12-08 04:02:32
问题 This is a followup to this question. I seem to have come across an edge case and I don't understand why I'm getting the wrong results. Using the data from the linked question, I can group them into combinations that use the same album, src, and background. For instance, using this data: CREATE TABLE reports (rep_id int primary key, data json); INSERT INTO reports (rep_id, data) VALUES (1, '{"objects":[{"album": 1, "src":"fooA.png", "pos": "top"}, {"album": 2, "src":"barB.png", "pos": "top"}],