postgresql-9.1

Postgres is ignoring a timestamp index, why?

蓝咒 提交于 2021-02-10 05:46:33
问题 I have the following tables: users (id, network_id) networks (id) private_messages (id, sender_id, receiver_id, created_at) I have indexes on users.network_id, and all 3 columns in private messages however the query is skipping the indexes and taking a very long time to run. Any ideas what is wrong in the query that is causing the index to be skipped? EXPLAIN ANALYZE SELECT COUNT(*) FROM "networks" WHERE ( networks.created_at BETWEEN ((timestamp '2013-01-01')) AND (( (timestamp '2013-01-31')

Find values not present in supplied list postgres

廉价感情. 提交于 2021-02-07 13:21:10
问题 I am trying to find a query that will tell me the values that are not in my database. Eg: select seqID, segment from flu where seqID IN (1,2,3,4,5,6,7,8,9). Now if my database doesn't have seqID's 3,8,9 how would I find/display only the missing seqID's. 回答1: First, since you appear to be new to Stackoverflow, here's a few etiquette and posting tips: Always include relevant version information. Here, you probably want to include PostgreSQL's version info Give a brief, concise description of

Join against the output of an array unnest without creating a temp table

余生长醉 提交于 2021-01-27 06:38:27
问题 I have a query in a UDF (shown below) which unnest() s an array of integers and joins against it, I have created a local temp table in my pgplsql UDF since I know this works. Is it possible to use unnest directly in a query to perform a join instead of having to create a temp table ? CREATE OR REPLACE FUNCTION search_posts( forum_id_ INTEGER, query_ CHARACTER VARYING, offset_ INTEGER DEFAULT NULL, limit_ INTEGER DEFAULT NULL, from_date_ TIMESTAMP WITHOUT TIME ZONE DEFAULT NULL, to_date_

How to clone a test database from a production one in one single action?

眉间皱痕 提交于 2020-12-01 03:24:23
问题 I am looking for a basic script/command that will create a copy of a live database (let name them mydb and mydb_test , both on the same server). Requirements it has to run even if the mydb_test already exists and have records it has to work even if mydb and mydb_test do have existing connections it have to clean the potentially existing database if necessary Hints: drop database cannot be used if you have existing connections 回答1: The simplest and fastest method to create a complete copy of

Select distinct values with count in PostgreSQL

匆匆过客 提交于 2020-08-26 19:54:54
问题 This is a heavily simplified version of an SQL problem I'm dealing with. Let's say I've got a table of all the cities in the world, like this: country city ------------ Canada Montreal Cuba Havanna China Beijing Canada Victoria China Macau I want to count how many cities each country has, so that I would end up with a table as such: country city_count ------------------ Canada 50 Cuba 10 China 200 I know that I can get the distinct country values with SELECT distinct country FROM T1 and I

How to install tablefunc in postgres on Mac OS X?

核能气质少年 提交于 2020-08-24 06:11:03
问题 I used StackBuilder to install Postgres 9.2 on my Mac OS X machine. Now I need to use tablefunc and it seems that the function is not available. How do I install the contrib package on the Mac? 回答1: As suggested by a_horse_with_no_name the solution was simple. I just had to execute: CREATE EXTENSION tablefunc; 来源: https://stackoverflow.com/questions/17935111/how-to-install-tablefunc-in-postgres-on-mac-os-x