postgresql-8.4

Get back the same result when trying to find different data

拟墨画扇 提交于 2020-01-15 11:19:30
问题 I can get the 15/02 - 21/06 date range data on every year from the query below. SELECT * FROM dim_date WHERE EXTRACT (MONTH FROM date_cal) BETWEEN 3 AND 5 OR (EXTRACT (MONTH FROM date_cal) = 2 AND EXTRACT (DAY FROM date_cal) >= 15) OR (EXTRACT (MONTH FROM date_cal) = 6 AND EXTRACT (DAY FROM date_cal) <= 21) But the problem is, when i want to find from year 2010 - 2012 , I get back the same result. Range that i want to get: 2010-02-15 - 2010-06-15 2011-02-15 - 2011-06-15 2012-02-15 - 2012-06

Get back the same result when trying to find different data

怎甘沉沦 提交于 2020-01-15 11:19:13
问题 I can get the 15/02 - 21/06 date range data on every year from the query below. SELECT * FROM dim_date WHERE EXTRACT (MONTH FROM date_cal) BETWEEN 3 AND 5 OR (EXTRACT (MONTH FROM date_cal) = 2 AND EXTRACT (DAY FROM date_cal) >= 15) OR (EXTRACT (MONTH FROM date_cal) = 6 AND EXTRACT (DAY FROM date_cal) <= 21) But the problem is, when i want to find from year 2010 - 2012 , I get back the same result. Range that i want to get: 2010-02-15 - 2010-06-15 2011-02-15 - 2011-06-15 2012-02-15 - 2012-06

postgresql create temp table could block data insertion?

白昼怎懂夜的黑 提交于 2020-01-07 04:53:04
问题 I am using postgresql 8.4 in backend. In backend I made a postgres function to get some data. The function won't write any data to DB so just read data from other tables. The function internally will create a temp table then return a set of records. When I monitoring the server I found out this function is blocking other connections doing data insertion. So just wondering creating temp table could block data insertion from other connections? Further question. I have a function A, inside this

PostgreSQL: return message after count = 0

时光怂恿深爱的人放手 提交于 2020-01-06 20:11:17
问题 I have maybe easy question, but I'm completely stucked. I have script SELECT COALESCE(COUNT(id), 0) as MyFiels from table It works fine and when I have zero value it shows 0. But I want that instead of 0, I can see one line = "NO RESULTS" for example. I tried: SELECT COALESCE(to_char(COUNT(id), 'NO RESULT')) as MyFiels from table And PostgreSQL shows error message: ERROR: "E" is not supported SQL state: 0A000 Where I'm incorrect? Any ideas? 回答1: I see what is the error, you are trying to use

PostgreSQL Trigger Exception

旧城冷巷雨未停 提交于 2020-01-06 14:13:44
问题 I'm having problems with creating this trigger in PostgreSQL 8.4. CREATE OR REPLACE FUNCTION tbi_Usuarios() RETURNS TRIGGER AS $tbi_Usuarios$ BEGIN IF trim(both ' ' from NEW.Nombre_usuario) = '' OR NEW.Nombre_usuario IS NULL THEN RAISE EXCEPTION 'Debes ingresar un nombre de usuario.'; END IF; IF NEW.Password = '' OR NEW.Password IS NULL THEN RAISE EXCEPTION 'Debes ingresar una contraseña correctamente'; ELSE NEW.Password := md5(NEW.Password); END IF; IF Fecha_registro IS NULL THEN NEW.Fecha

PostgreSQL: How to figure out missing numbers in a column using generate_series()?

给你一囗甜甜゛ 提交于 2020-01-03 15:35:07
问题 SELECT commandid FROM results WHERE NOT EXISTS ( SELECT * FROM generate_series(0,119999) WHERE generate_series = results.commandid ); I have a column in results of type int but various tests failed and were not added to the table. I would like to create a query that returns a list of commandid that are not found in results . I thought the above query would do what I wanted. However, it does not even work if I use a range that is outside the expected possible range of commandid (like negative

count() corresponding to max() of different values satisfying some condition

不问归期 提交于 2020-01-02 05:13:52
问题 I have the following tables: user_group usergrp_id bigint Primary Key usergrp_name text user user_id bigint Primary Key user_name text user_usergrp_id bigint user_loc_id bigint user_usergrp_id has its corresponding id from the user_group table user_loc_id has its corresponding id(branch_id) from the branch table. branch branch_id bigint Primary Key branch_name text branch_type smallint branch_type By default is set as 1. Although it may contain any value in between 1 and 4. user_projects proj

Aggregate strings in descending order in a PostgreSQL query

懵懂的女人 提交于 2020-01-02 00:59:13
问题 In addition to the question How to concatenate strings of a string field in a PostgreSQL 'group by' query? How can I sort employee in descending order? I am using PostgreSQL 8.4 which doesn't support string_agg() . I've tried to use the following, but it isn't supported: array_to_string(array_agg(employee ORDER BY employee DESC), ',') I'd appreciate any hint to the right answer. 回答1: In PostgreSQL 9.0 or later you can order elements inside aggregate functions: SELECT company_id, array_agg

How do I get tables in postgres using psycopg2?

非 Y 不嫁゛ 提交于 2019-12-31 09:07:10
问题 Can someone please explain how I can get the tables in the current database? I am using postgresql-8.4 psycopg2. 回答1: This did the trick for me: cursor.execute("""SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'""") for table in cursor.fetchall(): print(table) 回答2: pg_class stores all the required information. executing the below query will return user defined tables as a tuple in a list conn = psycopg2.connect(conn_string) cursor = conn.cursor() cursor.execute(

Get column values from multiple rows as array

冷暖自知 提交于 2019-12-25 07:48:26
问题 I am trying to fetch column values as an array in order to use them in the function array_agg_transfn() to calculate the median value as defined in the Postgres Wiki. The column values of a particular column I fetch based on the current row. For example, 13 rows below the current row. I tried using the following query: select a."Week_value", array_agg(a."Week_value") over(order by prod_name,week_date desc rows between 0 preceding and 12 following) from vin_temp_table But got this error