postgresql-8.4

Filter by date range (same month and day) across years

淺唱寂寞╮ 提交于 2019-12-19 18:23:30
问题 I have a PostgreSQL database with a table holding dates. Now I need to find all rows within the date range 15/02 until 21/06 (day/month) across all years. Example result: 1840-02-28 1990-06-21 1991-02-15 1991-04-25 1992-05-30 1995-03-04 1995-04-10 2001-02-03 2010-04-06 回答1: Assuming (with a leap of faith) that you want dates between certain days of the year regardless of the year (like if you're sending out a batch of birthday cards or something), you can set up a test with this: CREATE TABLE

Filter by date range (same month and day) across years

ε祈祈猫儿з 提交于 2019-12-19 18:23:24
问题 I have a PostgreSQL database with a table holding dates. Now I need to find all rows within the date range 15/02 until 21/06 (day/month) across all years. Example result: 1840-02-28 1990-06-21 1991-02-15 1991-04-25 1992-05-30 1995-03-04 1995-04-10 2001-02-03 2010-04-06 回答1: Assuming (with a leap of faith) that you want dates between certain days of the year regardless of the year (like if you're sending out a batch of birthday cards or something), you can set up a test with this: CREATE TABLE

GeoServer won't write to my PostgreSQL updateable view

我们两清 提交于 2019-12-19 10:35:32
问题 Following on from this earlier question I'm on PostgreSQL 8.4 and am having trouble with updatable views. I have a view: CREATE VIEW filedata_view AS SELECT num, id, ST_TRANSFORM(the_geom,900913) AS the_geom FROM filedata And want to update it from my application throw Geoserver. But get a error: <ServiceExceptionReport version="1.2.0" xmlns="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis

Analysing/Profiling queries on PostgreSQL

北城以北 提交于 2019-12-18 15:53:35
问题 I've just inherited an old PostgreSQL installation and need to do some diagnostics to find out why this database is running slow. On MS SQL you would use a tool such as Profiler to see what queries are running and then see how their execution plan looks like. What tools, if any, exist for PostgreSQL that I can do this with? I would appreciate any help since I´m quite new with Postgres. 回答1: Use pg_stat_statements extension to get long running queries. then use select* from pg_stat_statements

Fetch records that are non zero after the decimal point in PostgreSQL

强颜欢笑 提交于 2019-12-17 13:56:09
问题 I have a table with an amount field of type Numeric . It contains different amount values. For example 5.00 7.13 8.86 6.00 1.00 ... etc. I've to fetch only those records that are nonzero after the decimal point. ie, fetch only the records corresponding to the amounts 7.13 8.86 How can I do it? 回答1: numeric is exact! Unlike claimed by another answer, numeric is not a floating-point type , but an arbitrary precision type as defined by the SQL standard. Storage is exact . I quote the manual: The

sql to display all names in 1 row (1 string)

核能气质少年 提交于 2019-12-13 05:06:27
问题 ad_org table with column id & name ad_org ad_org_id | name ----------------------------------+----------- 357947E87C284935AD1D783CF6F099A1 | Spain 43D590B4814049C6B85C6545E8264E37 | Main 5EFF95EB540740A3B10510D9814EFAD5 | USA 2878085215E54C73A04D394BFD170733 | India 22669845D93A49A98932CE29AE02E0FD | Honkong how to get output of all names(in 1 string) in this way from the above database Spain | Main | USA | India | Honkong in 1 select statement. 回答1: Use string_agg . SELECT string_agg("name",

Dump or restore Postgresql databases without Postgis functions

…衆ロ難τιáo~ 提交于 2019-12-12 08:10:10
问题 I want to dump 4 databases from postgresql 8.4 to migrate to Postgresql 9.1. I use PostGis on the old Postgresql 8.4 with PgRouting so each database has around 1000 functions. Each time I export all databases, all functions are written in the dump. When I restore the backup file, I get some conflicts when I create an extension of postgis or pgrouting on Postgresql 9.1 Is there anyway to dump databases on 8.4 (create dbs, create schemas, create tables and data) without exporting fucntions as

Update tables logic

我们两清 提交于 2019-12-12 04:33:20
问题 I have two tables with triggers on them. FIRST CREATE OR REPLACE FUNCTION update_table() RETURNS trigger AS $BODY$ BEGIN IF TG_OP = 'UPDATE' THEN UPDATE filedata SET id=NEW.id,myData=NEW.myData,the_geom=ST_TRANSFORM(NEW.the_geom,70066) WHERE num=NEW.num; RETURN NEW; ELSEIF TG_OP = 'INSERT' THEN INSERT INTO filedata(num,id,myData,the_geom) VALUES (NEW.num,NEW.id,NEW.myData,ST_TRANSFORM(NEW.the_geom,70066)); INSERT INTO filestatus(id,name,status) VALUES (NEW.num,NEW.myData,'Не подтвержден');

String matching in PostgreSQL 8.4

半城伤御伤魂 提交于 2019-12-12 02:18:25
问题 I need to implement a regular expression (as I understand) matching in PostgreSQL 8.4. It seems regular expression matching are only available in 9.0+. My need is: When I give an input 14.1 I need to get these results: 14.1.1 14.1.2 14.1.Z ... But exclude: 14.1.1.1 14.1.1.K 14.1.Z.3.A ... The pattern is not limited to a single character. There is always a possibility that a pattern like this will be presented: 14.1.1.2K , 14.1.Z.13.A2 etc., because the pattern is provided the user. The

Replace a string with another string from a list depending on the value

淺唱寂寞╮ 提交于 2019-12-12 01:28:32
问题 Let's say I have this string: '2015/4/21 (Tuesday)' . I want to replace 'Tuesday' with another string, for example: 'cat'. The result should be: '2015/4/21 (cat)' . But I also want it to be dynamic, if it's 'Tuesday', then 'cat'. If it's 'Monday', then it's dog, etc. How do I do this in PostgreSQL 8.4? There is a similar post: postgresql - replace all instances of a string within text field But mine needs to replace something dynamic depending on the day and that post replaces a known value.