postgresql-9.1

Select query with offset limit is too much slow

旧城冷巷雨未停 提交于 2019-12-18 10:36:15
问题 I have read from internet resources that a query will be slow when the offset increases. But in my case I think its too much slow. I am using postgres 9.3 Here is the query ( id is primary key): select * from test_table offset 3900000 limit 100; It returns me data in around 10 seconds . And I think its too much slow. I have around 4 million records in table. Overall size of the database is 23GB . Machine configuration: RAM: 12 GB CPU: 2.30 GHz Core: 10 Few values from postgresql.conf file

Connection refused (PGError) (postgresql and rails)

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-18 03:59:04
问题 I keep getting this error when i try to run my localhost using "$rails s": (Mac OSX 10.8.3) (ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.3.0]) (Rails 3.2.11) (psql (PostgreSQL) 9.2.2 ) **installed with homebrew I have been doing a lot of uninstalling postgresql and reinstalling so I have a hunch that there may be conflicting libraries somewhere...i just dont know where to start. I had Postgresql 9.1 and 9.2 in the same folder and just moved 9.1 into the trash. Here is the

Connection refused (PGError) (postgresql and rails)

浪子不回头ぞ 提交于 2019-12-18 03:58:56
问题 I keep getting this error when i try to run my localhost using "$rails s": (Mac OSX 10.8.3) (ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.3.0]) (Rails 3.2.11) (psql (PostgreSQL) 9.2.2 ) **installed with homebrew I have been doing a lot of uninstalling postgresql and reinstalling so I have a hunch that there may be conflicting libraries somewhere...i just dont know where to start. I had Postgresql 9.1 and 9.2 in the same folder and just moved 9.1 into the trash. Here is the

How to change schema of multiple PostgreSQL tables in one operation?

丶灬走出姿态 提交于 2019-12-17 21:53:08
问题 I have a PostgreSQL 9.1 database with 100 or so tables that were loaded into the 'public' schema. I would like to move those tables (but not all of the functions in 'public') to a 'data' schema. I know that I can use the following to move 1 table at a time. ALTER TABLE [tablename] SET SCHEMA [new_schema] Is it possible to move all of the tables to the new schema in one operation? If so, what would be the most efficient way to accomplish this task? 回答1: DO will do the trick: DO $$ DECLARE row

How to tell if record has changed in Postgres

馋奶兔 提交于 2019-12-17 20:24:38
问题 I have a bit of an "upsert" type of question... but, I want to throw it out there because it's a little bit different than any that I've read on stackoverflow. Basic problem. I'm working on moving from mysql to PostgreSQL 9.1.5 (hosted on Heroku). As a part of that, I need to import multiple CSV files everyday. Some of the data is sales information and is almost guaranteed to be new and need to be inserted. But, other parts of the data is almost guaranteed to be the same. For example, the csv

How to take backup of functions only in Postgres

若如初见. 提交于 2019-12-17 17:44:24
问题 I want to take backup of all functions in my postgres database.How to take backup of functions only in Postgres? 回答1: use pg_getfunctiondef ; see system information functions. pg_getfunctiondef was added in PostgreSQL 8.4. SELECT pg_get_functiondef('proc_name'::regproc); To dump all functions in a schema you can query the system tables in pg_catalog ; say if you wanted everything from public : SELECT pg_get_functiondef(f.oid) FROM pg_catalog.pg_proc f INNER JOIN pg_catalog.pg_namespace n ON

How to use SQL LIKE condition with multiple values in PostgreSQL?

守給你的承諾、 提交于 2019-12-17 17:37:31
问题 Is there any shorter way to look for multiple matches: SELECT * from table WHERE column LIKE "AAA%" OR column LIKE "BBB%" OR column LIKE "CCC%" This questions applies to PostgreSQL 9.1, but if there is a generic solution it would be even better. 回答1: Perhaps using SIMILAR TO would work ? SELECT * from table WHERE column SIMILAR TO '(AAA|BBB|CCC)%'; 回答2: Using array or set comparisons: create table t (str text); insert into t values ('AAA'), ('BBB'), ('DDD999YYY'), ('DDD099YYY'); select str

PostgreSQL next value of the sequences?

谁说我不能喝 提交于 2019-12-17 10:56:24
问题 I am using PostgreSQL for my Codeigniter website. I am using grocery crud for add, edit and delete operations. While doing an edit or add, I want to rename an uploaded file dynamically based on the id of the content. I am able to do this using grocery crud's callback_after_upload function. I want a next id of the content while adding a new content. I tried to use nextval() function, but sequence gets incremented with it. How can get the last value of the sequence without using nextval()

Error when creating unaccent extension on PostgreSQL

China☆狼群 提交于 2019-12-17 10:52:08
问题 I am trying to configure PostgreSQL to use fulltext search in my rails app as mentioned in this Railscast. I am using a fresh Ubuntu 12.04 server running PostgreSQL 9.1.5 installed using apt-get with the ppa:pitti/postgresql with precise . I get the following error when trying to run the migration and when I try the same command in the psql console with the peer postgres user: postgres=# CREATE EXTENSION unaccent; ERROR: could not open extension control file "/usr/share/postgresql/9.1

Set Order By to ignore punctuation on a per-column basis

梦想与她 提交于 2019-12-14 04:16:40
问题 Is it possible to order the results of a PostgreSQL query by a title field that contains characters like [](),; etc but do so ignoring these punctuation characters and sorting only by the text characters? I've read articles on changing the database collation or locale but have not found any clear instructions on how to do this on an existing database an on a per-column basis. Is this even possible? 回答1: If you want to have this ordering in one particular query you can ORDER BY regexp_replace