postgresql-9.1

PostgreSQL select result size

社会主义新天地 提交于 2019-12-12 01:33:25
问题 I have a table in PostgreSQL DB and make a select from this table with some constraints, and than I want to know how much disk space does this select has. I know that there is a postgres function pg_total_relation_size that gives me the size of some table in DB, but how can I find the 'subtable' size? Any Ideas? I use PostgreSQL 9.1 回答1: To get the data size, allowing for TOAST compression, etc: regress=> SELECT sum(pg_column_size(devices)) FROM devices WHERE country = 'US'; sum ----- 105 (1

Detect role in Postgresql dynamically

拜拜、爱过 提交于 2019-12-12 00:52:44
问题 I have been trying to create a script that detects that a role already excists and if it does it should revoke all privileges. This works fine doing it like this: DO $$DECLARE count int; BEGIN SELECT count(*) INTO count FROM pg_roles WHERE rolname = 'superman'; IF count > 0 THEN REVOKE ALL PRIVILEGES ON TABLE FROM superman; END IF; END$$; But now I want this to be dynamic per environment since I will be using different role names per environment. So I tried to use the \set mechanism but that

How to show all date from a certain Month by horizontally?

与世无争的帅哥 提交于 2019-12-11 17:51:07
问题 I have database table in postgreSQL name as "time" like: | Name | | Date1 | |AttendHour1| | Date2 | |AttendHour2| --------------------------------------------------------------------- | Zakir1 | | 2018-10-01 | | 8.00 | | 2018-10-02 | | 8.00 | | Zakir2 | | 2018-10-01 | | 9.00 | | 2018-10-02 | | 9.00 | | Zakir3 | | 2018-10-01 | | 7.00 | | 2018-10-02 | | 7.00 | From this table I want the result like.. | Name | | 2018-10-01 | | 2018-10-02 | ---------------------------------------- | Zakir1 | | 8

Is it possible to create “Insensitive Table and Column name” in PostgreSQL

旧城冷巷雨未停 提交于 2019-12-11 16:52:22
问题 I am working on PostgreSQL 9.2 and i want to create a table with capital letter without using double quotes.Is it possible by any how? means CREATE TABLE STUDENT(NAME VARCHAR(50)); i want the table name must be look like "STUDENT" But postgresql automatically convert it into "student". So is there any way exist to disable sensitive property of postgresql for column and table names? thank you. 来源: https://stackoverflow.com/questions/23217205/is-it-possible-to-create-insensitive-table-and

What is the best way to replace a string with another string on entire table?

空扰寡人 提交于 2019-12-11 14:58:37
问题 My question is similar to below but I want to replace it for any column: postgresql - replace all instances of a string within text field for instance - replace all instances of cat with dog in entire table(all rows) I am expecting something like below query to work for all columns(without specifying the column name in update query). UPDATE table_name SET information_schema.columns replace (information_schema.columns, 'old_value', 'new_value'); which actually doesn't seems to work. Any

Setting PostgreSQL application_name on Heroku

南笙酒味 提交于 2019-12-11 11:59:19
问题 application_name is a PostgreSQL specific connection parameter which each client can (and should) set when connecting. It later on helps DBAs and operations staff correlate misbehaving queries with a particular bit of application code. This SO question explains how to set application_name using SQLAlchemy, but unfortunately, it doesn't work on Heroku, because setting application_name was added on the PostgreSQL 8.5 branch (which was only released as 9.0 ) whereas the version of PostgreSQL

ILIKE Match Word Boundaries PostgreSQL 9

若如初见. 提交于 2019-12-11 09:42:54
问题 When using the LIKE/ILIKE operator in PostgreSQL 9 is it possible to match word boundaries without having to use full blown ~ operator regular expressions? For example SELECT 'Super fast training' ILIKE '%train\M%' as match; Where \M is the boundary at the end of a word and match returns false Thanks, Mark 回答1: you can do it with following trick: SELECT ' ' || 'Super fast training' ILIKE '%train %' but I don't hink so it is a good idea. You can use regular expression or PostgreSQL fulltext

field value between date range

匆匆过客 提交于 2019-12-11 09:06:55
问题 Please, can someone help me, how to get information of doc status... Generally, I need for given period of time (start date, end date filters) to check if document is Active (A) or Inactive (I) Table Documents ID Doc Date Status 1 11 1.1.2012. A 2 11 1.4.2012. I 3 11 25.4.2012. A 4 11 1.6.2012. I 5 22 18.4.2012. A 6 22 30.4.2012. I Dynamic filters: @start,@end Example: @start= 2.3.2012 @end=5.5.2012 Result should be 11 2.3.-1.4. Status=A 1.4.-25.4 Status=I 25.4.-5.5. Status=A 22 2.3.-18.4.

Adding columns of two relations in postgresql

倖福魔咒の 提交于 2019-12-11 05:38:27
问题 I have two relations such as relation1 and relation2. relation1 has columns of A,B,C and relation2 has columns of D,E,F. I want to add A of relation1 with D of relation2 where C = F. For the C values which do not exist in relation2 must appear and F values which do not appear in relation1 also must appear How to do this postgresql? 回答1: Use a FULL [OUTER] JOIN to include rows from either side without a matching row on the other side: SELECT COALESCE(r1.a, 0) + COALESCE(r2.d, 0) AS a_d FROM

gpload utility in greenplum

别来无恙 提交于 2019-12-11 04:22:40
问题 Can anyone help me with the gpload utility in greenplum ? I am doing this for the first time, I have created the control file as per the help command, but getting some gpfdist connection error. Is there any reference material on gpload utility or some examples I can refer to? I getting below error while using gpload: 2013-05-21 09:34:20|INFO|started gpfdist -p 9096 -P 9097 -f "gpload.test.txt" -t 30 "2013-05-21 09:34:23|ERROR|ERROR: connection with gpfdist failed for gpfdist://<host-ip>:9096