postgresql-9.2

pg_listening_channels() is not returning the channels name

≯℡__Kan透↙ 提交于 2019-12-24 18:06:31
问题 1) i want to know the channels name which are listing on my database but pg_listening_channels() name always returning null value (blank) even some clients are listening on this database. below is my pgsql code. is any thing wrong in this code. CREATE OR REPLACE FUNCTION query_trigger() RETURNS trigger AS $BODY$ DECLARE send_message text; queryString text; channelNameArray text[]; channelNames text; BEGIN queryString = current_query(); channelNameArray = pg_listening_channels(); channelNames

Joining two tables with aggregates

落爺英雄遲暮 提交于 2019-12-24 10:45:04
问题 I've got two tables described below: CREATE TABLE categories ( id integer NOT NULL, category integer NOT NULL, name text, CONSTRAINT kjhfskfew PRIMARY KEY (id) ) WITH ( OIDS=FALSE ); CREATE TABLE products_ ( id integer NOT NULL, date date, id_employee integer, CONSTRAINT grh PRIMARY KEY (id) ) WITH ( OIDS=FALSE ); Now I have to do report in which I need following information: categories.category, categories.name (all of them, so string_agg is ok) - could be many assigned to one category and

SqlServer to Postgres DDL migration/conversion

断了今生、忘了曾经 提交于 2019-12-24 09:26:45
问题 We're looking to migrate from MSSQL to Postgres. I'm intending on using sql servers bcp tool for generating csv that we'll import into postgres with the bulk copy features. We are however, having trouble getting the DDL migrated. We've. I've gotten it to work by massaging the DDL generated by MMSQL by hand but We need something automated since we have a moving target (still adding tables, columns etc.) and will need to do this more than once. We're open to commercial and open source products

Get exact result for number division

谁都会走 提交于 2019-12-24 06:07:36
问题 SELECT 9/2 gives 4 Why gives postgresql automatically rounded result? There are some option for prevent this? (That is, I need that after division, if result is float, returns exactly and not rounded result). UPDATE : for example from function, I need return floating number CREATE OR REPLACE FUNCTION division_test (arg1 INTEGER, arg2 INTEGER,) RETURNS NUMERIC AS $$ BEGIN RETURN arg1 / arg2; END; $$ LANGUAGE plpgsql; SELECT division_test (9,2) result: 4 How to solve this problem? 回答1: Without

Gitlab repository does not exists issue

时光总嘲笑我的痴心妄想 提交于 2019-12-24 03:06:05
问题 Facing issue with gitlab repository not available. When accessing project form gitlab page it shows below error No repository The repository for this project does not exist. This means you can not push code until you create an empty repository or import existing one. When check over project details from root login below is problem Project info: Name: app Namespace: Administrator Owned by: Administrator Created by: Administrator Created on: May 20, 2016 9:08am http: http://192.168.1.123/root

postgresql-sort array by words in each elements

你。 提交于 2019-12-24 00:53:16
问题 There is string array ARRAY['CAT','CAT DOG CAT','DOG Cat'] Now i want to sort this array on count of words in each element. I have tried but cannot get any success. I want this output ARRAY['CAT DOG CAT','DOG CAT','Cat'] How i can do this? 回答1: This does feel rather clumsy, but I can't think of a simpler solution right now: with val (col) as ( values (ARRAY['CAT','CAT DOG CAT','DOG Cat']) ), word_list as ( select unnest(col) as pc from val ), wc as ( select array_length(string_to_array(pc, '

Remove duplicates from table based on multiple criteria and persist to other table

北城余情 提交于 2019-12-24 00:44:16
问题 I have a taccounts table with columns like account_id(PK) , login_name , password , last_login . Now I have to remove some duplicate entries according to a new business logic. So, duplicate accounts will be with either same email or same ( login_name & password ). The account with the latest login must be preserved. Here are my attempts (some email values are null and blank) DELETE FROM taccounts WHERE email is not null and char_length(trim(both ' ' from email))>0 and last_login NOT IN (

Why does a PostgreSQL SELECT query return different results when a schema name is specified?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 21:32:48
问题 I have a PostgreSQL database table with 4 columns - labeled column_a, column_b, etc. I want to query this table with a simple select query: select * from table_name; I get a handful of results looking like: column_a | column_b ---------+--------- 'a value'|'b_value' But when I use this query: select * from schema_name.table_name; I get the full result: column_a | column_b | column_c | column_d ---------+----------+----------+--------- 'a value'|'b value' |'c value' |'d_value' Columns c and d

Return array of years as year ranges

二次信任 提交于 2019-12-23 16:33:21
问题 I'm attempting to query a table which contains a character varying[] column of years, and return those years as a string of comma-delimited year ranges. The year ranges would be determined by sequential years present within the array, and years/year ranges which are not sequential should be separated be commas. The reason the data-type is character varying[] rather than integer[] is because a few of the values contain ALL instead of a list of years. We can omit these results. So far I've had

Return array of years as year ranges

我的未来我决定 提交于 2019-12-23 16:32:40
问题 I'm attempting to query a table which contains a character varying[] column of years, and return those years as a string of comma-delimited year ranges. The year ranges would be determined by sequential years present within the array, and years/year ranges which are not sequential should be separated be commas. The reason the data-type is character varying[] rather than integer[] is because a few of the values contain ALL instead of a list of years. We can omit these results. So far I've had