PASTEBIN
| #1 paste tool since 2002
create new paste
tools
api
archive
real-time
faq
PASTEBIN
create new paste
trending pastes
sign up
login
my settings
my profile
Public Pastes
PowerISO 5.0 Multi...
13 sec ago
Untitled
32 sec ago
Untitled
8 sec ago
Untitled
27 sec ago
Untitled
11 sec ago
Untitled
21 sec ago
Watch Live Brumbie...
1 min ago
Control C202E
27 sec ago
New Paste
CREATE OR REPLACE FUNCTION near_hospital(text) RETURNS text AS $$ DECLARE pojnt ALIAS FOR $1; -- pojnt will hold a point geometry where the emergency got reported distances RECORD; hospital RECORD; nearest RECORD; BEGIN select 'inf'::float8 as dist, null::text as gid INTO nearest; -- In the FOR I am going to select the 3 most near hospitals there are within the region to the point using distance() -- using && to try to minimize time and choosing a bigger expand box and selecting the distance from the accident -- to the hospital which is less than 150km @@ raise notice 'Entering the FOR IN %', timeofday() ; FOR distances IN select astext(h.the_geom) as hospital_location from hospitals h where ( h.the_geom && expand (pointfromtext(pojnt),100000) and distance ( h.the_geom , pointfromtext(pojnt) ) < 150000 ) order by distance (h.the_geom , pointfromtext(pojnt)) ASC limit 3 LOOP -- here i am getting all the results given and passing the location to the give_source function which basically -- gets the nearest distance on a road .. using the same where clause of the select astext(h.the_geom) etc -- give_target function is being given to see the nearest node where the accident happened -- a shootingstar_sp query is fired to give the length @@ raise notice 'entering shooting star %', timeofday() ; select gid, the_geom, length(the_geom) AS dist INTO hospital from shootingstar_sp ( 'streets', ( select s.gid from streets s, hospitals h where source = ( select give_source(distances.hospital_location,100000,150000)) limit 1 ) , ( select gid from streets where target = (select give_target(pojnt,100000,150000)) limit 1 ) , 5000, 'length', true, true ); -- here i am checking about the distance .. if the current distance is smaller than the other distance the values -- are changed and also the gid (which is being used as the new hospital location) is updated with the astext(the_geom) -- of the new location .. Here I am using some raise notices to check the data is being changed well. @@ raise notice 'before IF %', timeofday() ; IF hospital.dist < nearest.dist THEN nearest.dist := hospital.dist; raise notice 'value of nearest.dist is %', nearest.dist; raise notice 'value of hospital.gid is %', hospital.gid; raise notice 'value of nearest.gid is %', nearest.gid; nearest.gid := distances.hospital_location; raise notice 'value of 2ND nearest.gid is %', nearest.gid; END IF; @@ raise notice 'after if %', timeofday() ; @@ raise notice 'before end of loop %', timeofday() ; END LOOP; @@ raise notice 'after end of loop before returning %', timeofday() ; RETURN nearest.gid; END; $$ language 'plpgsql'; PASTING THE RESULT OF : EXPLAIN ANALYZE select * from near_hospital ('POINT(640740 225416)'); -- Executing query: EXPLAIN ANALYZE select * from near_hospital ('POINT(640740 225416)'); NOTICE: value of nearest.dist is 585.966565014107 NOTICE: value of hospital.gid is 12712 NOTICE: value of nearest.gid is <NULL> NOTICE: value of 2ND nearest.gid is POINT(640607.6248615 224673.124400562) NOTICE: value of nearest.dist is 91.0322939509899 NOTICE: value of hospital.gid is 38600 NOTICE: value of nearest.gid is POINT(640607.6248615 224673.124400562) NOTICE: value of 2ND nearest.gid is POINT(640952.4998615 224309.563400563) Total query runtime: 113047 ms. 2 rows retrieved. "Function Scan on near_hospital (cost=0.00..0.01 rows=1 width=32) (actual time=112910.541..112910.543 rows=1 loops=1)" "Total runtime: 112910.585 ms"
Optional Paste Settings
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
HTML 5
Java
JavaScript
Lua
None
Perl
PHP
Python
Rails
-------------
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
ActionScript
ActionScript 3
Ada
ALGOL 68
Apache Log
AppleScript
APT Sources
ASM (NASM)
ASP
autoconf
Autohotkey
AutoIt
Avisynth
Awk
BASCOM AVR
Bash
Basic4GL
BibTeX
Blitz Basic
BNF
BOO
BrainFuck
C
C for Macs
C Intermediate Language
C#
C++
C++ (with QT extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
ChaiScript
Clojure
Clone C
Clone C++
CMake
COBOL
CoffeeScript
ColdFusion
CSS
Cuesheet
D
DCS
Delphi
Delphi Prism (Oxygene)
Diff
DIV
DOS
DOT
E
ECMAScript
Eiffel
Email
EPC
Erlang
F#
Falcon
FO Language
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
Game Maker
GDB
Genero
Genie
GetText
Go
Groovy
GwBasic
Haskell
HicEst
HQ9 Plus
HTML
HTML 5
Icon
IDL
INI file
Inno Script
INTERCAL
IO
J
Java
Java 5
JavaScript
jQuery
KiXtart
Latex
Liberty BASIC
Linden Scripting
Lisp
LLVM
Loco Basic
Logtalk
LOL Code
Lotus Formulas
Lotus Script
LScript
Lua
M68000 Assembler
MagikSF
Make
MapBasic
MatLab
mIRC
MIX Assembler
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MPASM
MXML
MySQL
newLISP
None
NullSoft Installer
Oberon 2
Objeck Programming Langua
Objective C
OCalm Brief
OCaml
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
Pascal
PAWN
PCRE
Per
Perl
Perl 6
PHP
PHP Brief
Pic 16
Pike
Pixel Bender
PL/SQL
PostgreSQL
POV-Ray
Power Shell
PowerBuilder
ProFTPd
Progress
Prolog
Properties
ProvideX
PureBasic
PyCon
Python
q/kdb+
QBasic
R
Rails
REBOL
REG
Robots
RPM Spec
Ruby
Ruby Gnuplot
SAS
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
SQL
SystemVerilog
T-SQL
TCL
Tera Term
thinBasic
TypoScript
Unicon
UnrealScript
Vala
VB.NET
VeriLog
VHDL
VIM
Visual Pro Log
VisualBasic
VisualFoxPro
WhiteSpace
WHOIS
Winbatch
XBasic
XML
Xorg Config
XPP
YAML
Z80 Assembler
ZXBasic
Paste Expiration:
Never
10 Minutes
1 Hour
1 Day
1 Month
Paste Exposure:
Public
Unlisted
Private (members only)
Paste Name / Title:
Hello
Guest
Sign Up
or
Login
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login