postgresql-9.3

How to get value in one row in postgreSQL?

寵の児 提交于 2019-12-24 07:05:07
问题 I have database table name emp_leave in postgreSQL9.3 like |emp_name|department|ann_leave|med_leave|cas_leave|org_ann_lv|org_med_lv|org_cas_lv| | Tame | IT | | | 3 | | | 25 | | Tame | IT | 4 | | | 20 | | | | Tame | IT | | 3 | | | 30 | | I want the query result like |emp_name|department|ann_leave|med_leave|cas_leave|org_ann_lv|org_med_lv|org_cas_lv| | Tame | IT | 4 | 3 | 3 | 20 | 30 | 25 | 回答1: You want aggregation : select el.emp_name, el.department, max(el.ann_leave), . . . , max(el.org_cas

Most efficient way to find points within a certain radius from a given point

元气小坏坏 提交于 2019-12-24 01:18:42
问题 I've read several questions + answers here on SO about this theme, but I can't understand which is the common way (if there is one...) to find all the points whithin a "circle" having a certain radius, centered on a given point. In particular I found two ways that seem the most convincing: select id, point from my_table where st_Distance(point, st_PointFromText('POINT(-116.768347 33.911404)', 4326)) < 10000; and: select id, point from my_table where st_Within(point, st_Buffer(st_PointFromText

select from … - based on a value in JSON format

烈酒焚心 提交于 2019-12-23 13:58:35
问题 Let's say I have a database table with several common columns such as name, gender, age, ... Besides I have an additional column using the JSON datatype (available from Postgres 9.2) with arbitrary length and arbitrary fields in JSON: {"occupation":"football"} {"occupation":"football", "hair-colour":"black"} {"hair-style":"curly"} Using new features of Postgres 9.3 I want to return all rows with occupation = football for instance. Something like this pseudo: select * from table where json

What is the scope of a PostgreSQL Temp Table?

我是研究僧i 提交于 2019-12-23 09:07:05
问题 I have googled quite a bit, and I have fairly decent reading comprehension, but I don't understand if this script will work in multiple threads on my postgres/postgis box. Here is the code: Do $do$ DECLARE x RECORD; b int; begin create temp table geoms (id serial, geom geometry) on commit drop; for x in select id,geom from asdf loop truncate table geoms; insert into geoms (geom) select someGeomfield from sometable where st_intersects(somegeomfield,x.geom); ----do something with the records in

PSQL: How can I prevent any output on the command line?

雨燕双飞 提交于 2019-12-22 11:38:30
问题 My problem: I'm trying to run a database generation script at the command line via a batch file as part of a TFS build process to enable nightly testing on a known dataset. The scripts we run are outputting Notices, Warnings and some Errors on the command line. I would like to suppress at least the Notices and Warnings, and if possible the Errors as they don't seem to have an impact on the overall success of the scripts. This output seems to be affecting the success or failure of the process

How to get the current free disk space in Postgres?

帅比萌擦擦* 提交于 2019-12-22 03:53:08
问题 I need to be sure that I have at least 1Gb of free disk space before start doing some work in my database. I'm looking for something like this: select pg_get_free_disk_space(); Is it possible? (I found nothing about it in docs). PG: 9.3 & OS: Linux/Windows 回答1: PostgreSQL does not currently have features to directly expose disk space. For one thing, which disk? A production PostgreSQL instance often looks like this: /pg/pg94/ : a RAID6 of fast reliable storage on a BBU RAID controller in WB

Partition pruning based on check constraint not working as expected

橙三吉。 提交于 2019-12-22 01:14:38
问题 Why is the table "events_201504" included in the query plan below? Based on my query and the check constraint on that table I would expect the query planner to be able to prune it entirely: database=# \d events_201504 Table "public.events_201504" Column | Type | Modifiers ---------------+-----------------------------+--------------------------------------------------------------- id | bigint | not null default nextval('events_id_seq'::regclass) created_at | timestamp without time zone |

Dapper Bulk Insert Returning Serial IDs

泄露秘密 提交于 2019-12-20 19:47:22
问题 I am attempting to perform a bulk-insert using Dapper over Npgsql, that returns the ids of the newly inserted rows. The following insert statement is used in both of my examples: var query = "INSERT INTO \"MyTable\" (\"Value\") VALUES (@Value) RETURNING \"ID\""; First, I attempted to add an array of objects with a "Value" property: var values = new[] { new { Value = 0.0 }, new { Value = 0.5 } }; var ids = connection.Query<int>(query, values); However, that fails with the NpgsqlException:

indexing and query high dimensional data in postgreSQL

╄→гoц情女王★ 提交于 2019-12-20 18:30:15
问题 I want to index data in height dimensions (128 dimensional vectors of integers in range of [0,254] are possible): | id | vector | | 1 | { 1, 0, ..., 254} | | 2 | { 2, 128, ...,1} | | . | { 1, 0, ..., 252} | | n | { 1, 2, ..., 251} | I saw that PostGIS implemented R-Trees. So can I use these trees in PostGIS to index and query multidimensional vectors in Postgres? I also saw that there is a index implementation for int arrays. Now I have questions about how to perform a query. Can I perform a

How to refresh all materialized views in Postgresql 9.3 at once?

放肆的年华 提交于 2019-12-20 11:37:13
问题 I am loading a bunch of data into a PostgresQL 9.3 database and then I want to refresh all materialized views that depend on the updated tables. Is there a way to do it automatically instead of going through each view and refreshing them one by one? I know that Oracle can do that rather easily but I did not find anything after combing through PostgreSQL documentation. 回答1: Looks like current version of PostgreSQL (9.3.1) does not have such functionality, have had to write my own function