Hex Artifact Content
Not logged in

Artifact 79a84ad020572f3a0bf81004be49dac7aa185c14:

Wiki page [tutorial] by sandro 2013-08-13 15:48:47.
0000: 44 20 32 30 31 33 2d 30 38 2d 31 33 54 31 35 3a  D 2013-08-13T15:
0010: 34 38 3a 34 37 2e 38 32 32 0a 4c 20 74 75 74 6f  48:47.822.L tuto
0020: 72 69 61 6c 0a 50 20 37 37 66 34 36 30 36 30 33  rial.P 77f460603
0030: 35 31 64 34 39 36 63 33 65 36 65 34 61 34 30 35  51d496c3e6e4a405
0040: 39 33 31 39 66 66 39 38 31 31 31 37 64 37 36 0a  9319ff981117d76.
0050: 55 20 73 61 6e 64 72 6f 0a 57 20 31 31 32 33 34  U sandro.W 11234
0060: 0a 3c 68 33 3e 61 62 6f 75 74 20 56 69 72 74 75  .<h3>about Virtu
0070: 61 6c 50 47 3c 2f 68 33 3e 0d 0a 3c 62 3e 56 69  alPG</h3>..<b>Vi
0080: 72 74 75 61 6c 50 47 3c 2f 62 3e 20 69 73 20 61  rtualPG</b> is a
0090: 20 3c 69 3e 6c 6f 61 64 61 62 6c 65 20 64 79 6e   <i>loadable dyn
00a0: 61 6d 69 63 20 65 78 74 65 6e 73 69 6f 6e 20 6d  amic extension m
00b0: 6f 64 75 6c 65 3c 2f 69 3e 20 66 6f 72 20 62 6f  odule</i> for bo
00c0: 74 68 20 3c 62 3e 53 51 4c 69 74 65 3c 2f 62 3e  th <b>SQLite</b>
00d0: 20 61 6e 64 20 3c 62 3e 53 70 61 74 69 61 4c 69   and <b>SpatiaLi
00e0: 74 65 3c 2f 62 3e 3b 20 69 74 73 20 69 6e 74 65  te</b>; its inte
00f0: 6e 64 65 64 20 73 63 6f 70 65 20 69 73 20 73 75  nded scope is su
0100: 70 70 6f 72 74 69 6e 67 20 64 69 72 65 63 74 20  pporting direct 
0110: 64 61 74 61 20 65 78 63 68 61 6e 67 65 20 66 6f  data exchange fo
0120: 72 6d 2f 74 6f 20 3c 62 3e 50 6f 73 74 67 72 65  rm/to <b>Postgre
0130: 53 51 4c 3c 2f 62 3e 20 61 6e 64 20 3c 62 3e 50  SQL</b> and <b>P
0140: 6f 73 74 47 49 53 3c 2f 62 3e 20 74 61 72 67 65  ostGIS</b> targe
0150: 74 73 20 73 69 6d 70 6c 79 20 75 73 69 6e 67 20  ts simply using 
0160: 62 61 73 69 63 2c 20 70 6c 61 69 6e 20 3c 69 3e  basic, plain <i>
0170: 53 51 4c 20 73 74 61 74 65 6d 65 6e 74 73 3c 2f  SQL statements</
0180: 69 3e 2e 3c 62 72 3e 0d 0a 54 68 65 20 65 78 74  i>.<br>..The ext
0190: 65 6e 73 69 6f 6e 20 6d 6f 64 75 6c 65 20 73 69  ension module si
01a0: 6d 70 6c 79 20 69 73 20 61 6e 20 6f 72 64 69 6e  mply is an ordin
01b0: 61 72 79 20 3c 69 3e 64 79 6e 61 6d 69 63 20 6c  ary <i>dynamic l
01c0: 69 62 72 61 72 79 3c 2f 69 3e 20 28 3c 62 3e 2e  ibrary</i> (<b>.
01d0: 64 6c 6c 3c 2f 62 3e 20 6f 6e 20 57 69 6e 64 6f  dll</b> on Windo
01e0: 77 73 2c 20 3c 62 3e 2e 73 6f 3c 2f 62 3e 20 6f  ws, <b>.so</b> o
01f0: 6e 20 55 6e 69 78 20 61 6e 64 20 4c 69 6e 75 78  n Unix and Linux
0200: 2c 20 3c 62 3e 2e 64 79 6c 69 62 3c 2f 62 3e 20  , <b>.dylib</b> 
0210: 6f 6e 20 4d 61 63 20 4f 73 20 58 29 3b 20 73 6f  on Mac Os X); so
0220: 20 74 68 65 20 66 69 72 73 74 20 74 68 69 6e 67   the first thing
0230: 20 74 6f 20 62 65 20 64 6f 6e 65 20 69 6e 20 6f   to be done in o
0240: 72 64 65 72 20 74 6f 20 61 63 74 69 76 61 74 65  rder to activate
0250: 20 74 68 69 73 20 65 78 74 65 6e 73 69 6f 6e 20   this extension 
0260: 69 73 20 6c 6f 61 64 69 6e 67 20 74 68 65 20 63  is loading the c
0270: 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 6c 69 62  orresponding lib
0280: 72 61 72 79 20 66 72 6f 6d 20 61 20 76 61 6c 69  rary from a vali
0290: 64 20 53 51 4c 69 74 65 2f 53 70 61 74 69 61 4c  d SQLite/SpatiaL
02a0: 69 74 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 2e 0d  ite connection..
02b0: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c  .<verbatim>..SEL
02c0: 45 43 54 20 6c 6f 61 64 5f 65 78 74 65 6e 73 69  ECT load_extensi
02d0: 6f 6e 28 27 6c 69 62 76 69 72 74 75 61 6c 70 67  on('libvirtualpg
02e0: 2d 31 27 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 0d 0a 4e  -1');..------..N
02f0: 55 4c 4c 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e  ULL..</verbatim>
0300: 0d 0a 3c 74 61 62 6c 65 20 62 67 63 6f 6c 6f 72  ..<table bgcolor
0310: 3d 22 23 66 66 66 66 65 38 22 20 77 69 64 74 68  ="#ffffe8" width
0320: 3d 22 31 30 30 25 22 3e 0d 0a 3c 74 72 3e 3c 74  ="100%">..<tr><t
0330: 64 20 61 6c 69 67 6e 3d 22 63 65 6e 74 65 72 22  d align="center"
0340: 3e 3c 62 3e 55 73 65 66 75 6c 20 68 69 6e 74 73  ><b>Useful hints
0350: 20 61 6e 64 20 73 75 67 67 65 73 74 69 6f 6e 73   and suggestions
0360: 3a 20 74 72 6f 75 62 6c 65 73 68 6f 6f 74 69 6e  : troubleshootin
0370: 67 3c 2f 62 3e 3c 2f 74 64 3e 3c 2f 74 72 3e 0d  g</b></td></tr>.
0380: 0a 3c 74 72 3e 3c 74 64 3e 3c 68 72 3e 3c 2f 74  .<tr><td><hr></t
0390: 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64  d></tr>..<tr><td
03a0: 3e 0d 0a 54 68 69 73 20 6f 70 65 72 61 74 69 6f  >..This operatio
03b0: 6e 20 63 6f 75 6c 64 20 65 76 65 6e 74 75 61 6c  n could eventual
03c0: 6c 79 20 66 61 69 6c 20 66 6f 72 20 73 65 76 65  ly fail for seve
03d0: 72 61 6c 20 64 69 66 66 65 72 65 6e 74 20 72 65  ral different re
03e0: 61 73 6f 6e 73 3a 20 68 65 72 65 20 61 72 65 20  asons: here are 
03f0: 74 68 65 20 6d 6f 73 74 20 66 72 65 71 75 65 6e  the most frequen
0400: 74 73 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 59  ts:..<ul>..<li>Y
0410: 6f 75 20 61 72 65 20 75 73 69 6e 67 20 73 6f 6d  ou are using som
0420: 65 20 6f 64 64 20 76 65 72 73 69 6f 6e 20 6f 66  e odd version of
0430: 20 53 51 4c 69 74 65 33 2f 6c 69 62 73 71 6c 69   SQLite3/libsqli
0440: 74 65 33 20 66 6f 72 62 69 64 64 69 6e 67 20 74  te3 forbidding t
0450: 6f 20 6c 6f 61 64 20 61 6e 79 20 64 79 6e 61 6d  o load any dynam
0460: 69 63 20 65 78 74 65 6e 73 69 6f 6e 73 2e 3c 62  ic extensions.<b
0470: 72 3e 0d 0a 54 68 69 73 20 66 65 61 74 75 72 65  r>..This feature
0480: 20 63 6f 75 6c 64 20 65 76 65 6e 74 75 61 6c 6c   could eventuall
0490: 79 20 62 65 20 64 69 73 61 62 6c 65 64 20 61 74  y be disabled at
04a0: 20 62 75 69 6c 64 20 74 69 6d 65 3b 20 69 66 20   build time; if 
04b0: 74 68 69 73 20 69 73 20 79 6f 75 72 20 63 61 73  this is your cas
04c0: 65 20 79 6f 75 20 73 69 6d 70 6c 65 20 68 61 76  e you simple hav
04d0: 65 20 74 6f 20 73 77 69 74 63 68 20 74 6f 20 73  e to switch to s
04e0: 6f 6d 65 20 64 69 66 66 65 72 65 6e 74 20 53 51  ome different SQ
04f0: 4c 69 74 65 20 74 6f 6f 6c 6b 69 74 20 73 75 70  Lite toolkit sup
0500: 70 6f 72 74 69 6e 67 20 64 79 6e 61 6d 69 63 20  porting dynamic 
0510: 65 78 74 65 6e 73 69 6f 6e 20 6f 72 20 62 75 69  extension or bui
0520: 6c 64 20 6f 6e 65 20 62 79 20 79 6f 75 72 73 65  ld one by yourse
0530: 6c 66 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 54 68  lf.</li>..<li>Th
0540: 65 20 6f 70 65 72 61 74 69 6e 67 20 73 79 73 74  e operating syst
0550: 65 6d 20 63 6f 75 6c 64 20 62 65 20 75 6e 61 62  em could be unab
0560: 6c 65 20 74 6f 20 63 6f 72 72 65 63 74 6c 79 20  le to correctly 
0570: 6c 6f 63 61 74 65 20 74 68 65 20 64 79 6e 61 6d  locate the dynam
0580: 69 63 20 6c 69 62 72 61 72 79 20 74 6f 20 62 65  ic library to be
0590: 20 6c 6f 61 64 65 64 2e 3c 62 72 3e 0d 0a 54 68   loaded.<br>..Th
05a0: 65 20 6d 6f 73 74 20 72 65 63 65 6e 74 20 76 65  e most recent ve
05b0: 72 73 69 6f 6e 73 20 6f 66 20 53 51 4c 69 74 65  rsions of SQLite
05c0: 20 61 72 65 20 73 6d 61 72 74 20 65 6e 6f 75 67   are smart enoug
05d0: 68 20 74 6f 20 61 75 74 6f 6d 61 74 69 63 61 6c  h to automatical
05e0: 6c 79 20 68 61 6e 64 6c 65 20 61 6e 79 20 70 6c  ly handle any pl
05f0: 61 74 66 6f 72 6d 20 73 70 65 63 69 66 69 63 20  atform specific 
0600: 73 75 66 66 69 78 3a 20 73 6f 20 79 6f 75 20 61  suffix: so you a
0610: 72 65 20 6e 6f 20 6c 6f 6e 67 65 72 20 72 65 71  re no longer req
0620: 75 69 72 65 64 20 74 6f 20 73 70 65 63 69 66 79  uired to specify
0630: 20 61 6e 79 20 3c 62 3e 2e 64 6c 6c 3c 2f 62 3e   any <b>.dll</b>
0640: 20 6f 72 20 3c 62 3e 2e 73 6f 3c 2f 62 3e 20 73   or <b>.so</b> s
0650: 75 66 66 69 78 2e 20 49 66 20 79 6f 75 20 77 69  uffix. If you wi
0660: 73 68 20 74 6f 20 64 6f 20 73 6f 2c 20 79 6f 75  sh to do so, you
0670: 20 63 61 6e 20 65 76 65 6e 74 75 61 6c 6c 79 20   can eventually 
0680: 73 70 65 63 69 66 79 20 74 68 65 20 66 75 6c 6c  specify the full
0690: 20 70 61 74 68 20 6c 65 61 64 69 6e 67 20 74 6f   path leading to
06a0: 20 74 68 65 20 64 79 6e 61 6d 69 63 20 6c 69 62   the dynamic lib
06b0: 72 61 72 79 2c 20 74 68 69 73 20 69 6e 63 6c 75  rary, this inclu
06c0: 64 69 6e 67 20 61 6e 79 20 73 75 66 66 69 78 2e  ding any suffix.
06d0: 3c 62 72 3e 0d 0a 41 6e 79 77 61 79 20 74 68 65  <br>..Anyway the
06e0: 20 64 65 66 61 75 6c 74 20 62 65 68 61 76 69 6f   default behavio
06f0: 75 72 20 6f 66 20 3c 62 3e 6c 6f 61 64 5f 65 78  ur of <b>load_ex
0700: 74 65 6e 73 69 6f 6e 28 29 3c 2f 62 3e 20 69 73  tension()</b> is
0710: 20 74 68 65 20 6f 6e 65 20 74 6f 20 73 65 61 72   the one to sear
0720: 63 68 20 74 68 65 20 72 65 71 75 69 72 65 64 20  ch the required 
0730: 64 79 6e 61 6d 69 63 20 6c 69 62 72 61 72 79 20  dynamic library 
0740: 66 6f 6c 6c 6f 77 69 6e 67 20 74 68 65 20 73 74  following the st
0750: 61 6e 64 61 72 64 20 70 6c 61 74 66 6f 72 6d 20  andard platform 
0760: 73 70 65 63 69 66 69 63 20 72 75 6c 65 73 2e 0d  specific rules..
0770: 0a 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 54 68 65 20  .</li>..<li>The 
0780: 64 79 6e 61 6d 69 63 20 6c 69 62 72 61 72 79 20  dynamic library 
0790: 69 74 73 65 6c 66 20 63 6f 75 6c 64 20 62 65 20  itself could be 
07a0: 63 6f 72 72 65 63 74 6c 79 20 6c 6f 63 61 74 65  correctly locate
07b0: 64 2c 20 62 75 74 20 73 6f 6d 65 20 66 75 72 74  d, but some furt
07c0: 68 65 72 20 64 65 70 65 6e 64 69 6e 67 20 6c 69  her depending li
07d0: 62 72 61 72 79 20 63 6f 75 6c 64 20 6e 6f 74 2c  brary could not,
07e0: 20 74 68 75 73 20 66 6f 72 62 69 64 64 69 6e 67   thus forbidding
07f0: 20 74 6f 20 6c 6f 61 64 20 74 68 65 20 6d 61 69   to load the mai
0800: 6e 20 6c 69 62 72 61 72 79 2e 3c 62 72 3e 0d 0a  n library.<br>..
0810: 3c 75 3e 50 6c 65 61 73 65 20 6e 6f 74 65 3c 2f  <u>Please note</
0820: 75 3e 3a 20 3c 62 3e 56 69 72 74 75 61 6c 50 47  u>: <b>VirtualPG
0830: 3c 2f 62 3e 20 64 65 70 65 6e 64 73 20 6f 6e 20  </b> depends on 
0840: 74 68 65 20 50 6f 73 74 67 72 65 53 51 4c 20 6f  the PostgreSQL o
0850: 77 6e 20 63 6c 69 65 6e 74 20 6c 69 62 72 61 72  wn client librar
0860: 79 20 28 3c 62 3e 6c 69 62 70 71 3c 2f 62 3e 29  y (<b>libpq</b>)
0870: 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 49 6e 20 61  .</li>..<li>In a
0880: 6e 79 20 63 61 73 65 2c 20 69 66 20 79 6f 75 20  ny case, if you 
0890: 61 72 65 20 75 73 69 6e 67 20 73 6f 6d 65 20 69  are using some i
08a0: 6e 74 65 72 61 63 74 69 76 65 20 74 6f 6f 6c 20  nteractive tool 
08b0: 73 75 63 68 20 61 73 20 3c 62 3e 73 71 6c 69 74  such as <b>sqlit
08c0: 65 33 3c 2f 62 3e 2c 20 3c 62 3e 73 70 61 74 69  e3</b>, <b>spati
08d0: 61 6c 69 74 65 3c 2f 62 3e 20 6f 72 20 3c 62 3e  alite</b> or <b>
08e0: 73 70 61 74 69 61 6c 69 74 65 5f 67 75 69 3c 2f  spatialite_gui</
08f0: 62 3e 20 73 6f 6d 65 20 75 73 65 66 75 6c 20 61  b> some useful a
0900: 6e 64 20 6d 65 61 6e 69 6e 67 66 75 6c 20 65 72  nd meaningful er
0910: 72 6f 72 20 6d 65 73 73 61 67 65 20 77 69 6c 6c  ror message will
0920: 20 73 75 72 65 6c 79 20 62 65 20 64 69 73 70 6c   surely be displ
0930: 61 79 65 64 20 65 78 70 6c 61 69 6e 69 6e 67 20  ayed explaining 
0940: 74 68 65 20 66 61 69 6c 75 72 65 20 63 61 75 73  the failure caus
0950: 65 2e 3c 62 72 3e 0d 0a 54 68 69 73 20 63 6f 75  e.<br>..This cou
0960: 6c 64 20 6e 6f 74 20 62 65 20 73 75 70 70 6f 72  ld not be suppor
0970: 74 65 64 20 77 68 69 6c 65 20 61 74 74 65 6d 70  ted while attemp
0980: 74 69 6e 67 20 74 6f 20 6c 6f 61 64 20 61 6e 20  ting to load an 
0990: 65 78 74 65 6e 73 69 6f 6e 20 66 72 6f 6d 20 73  extension from s
09a0: 6f 6d 65 20 6c 61 6e 67 75 61 67 65 20 62 69 6e  ome language bin
09b0: 64 69 6e 67 20 28 65 2e 67 2e 20 3c 62 3e 2e 4e  ding (e.g. <b>.N
09c0: 45 54 3c 2f 62 3e 2c 20 3c 62 3e 50 79 74 68 6f  ET</b>, <b>Pytho
09d0: 6e 3c 2f 62 3e 20 6f 72 20 3c 62 3e 4a 61 76 61  n</b> or <b>Java
09e0: 3c 2f 62 3e 29 2e 0d 0a 49 6e 20 74 68 69 73 20  </b>)...In this 
09f0: 63 61 73 65 20 61 74 74 65 6d 70 74 69 6e 67 20  case attempting 
0a00: 74 6f 20 69 64 65 6e 74 69 66 79 20 74 68 65 20  to identify the 
0a10: 72 65 61 6c 20 65 72 72 6f 72 20 63 61 75 73 65  real error cause
0a20: 20 63 6f 75 6c 64 20 62 65 20 72 65 61 6c 6c 79   could be really
0a30: 20 70 61 69 6e 66 75 6c 20 64 75 65 20 74 6f 20   painful due to 
0a40: 70 6f 6f 72 20 61 6e 64 20 73 6c 6f 70 70 79 20  poor and sloppy 
0a50: 64 69 61 67 6e 6f 73 74 69 63 20 73 75 70 70 6f  diagnostic suppo
0a60: 72 74 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 54 68  rt.</li>..<li>Th
0a70: 65 72 65 20 61 72 65 20 6e 6f 20 75 6e 69 76 65  ere are no unive
0a80: 72 73 61 6c 20 72 75 6c 65 73 20 64 69 63 74 61  rsal rules dicta
0a90: 74 69 6e 67 20 77 68 65 72 65 20 74 6f 20 70 6c  ting where to pl
0aa0: 61 63 65 20 79 6f 75 72 20 65 78 74 65 6e 73 69  ace your extensi
0ab0: 6f 6e 20 6d 6f 64 75 6c 65 73 3b 20 61 20 67 6f  on modules; a go
0ac0: 6f 64 20 73 75 67 67 65 73 74 69 6f 6e 20 69 73  od suggestion is
0ad0: 20 74 6f 20 61 6c 77 61 79 73 20 70 6c 61 63 65   to always place
0ae0: 20 61 6c 6c 20 74 68 65 6d 20 69 6e 20 74 68 65   all them in the
0af0: 20 6d 6f 73 74 20 61 70 70 72 6f 70 72 69 61 74   most appropriat
0b00: 65 20 73 79 73 74 65 6d 20 64 69 72 65 63 74 6f  e system directo
0b10: 72 79 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d  ry.</li>..</ul>.
0b20: 0a 3c 62 3e 49 6d 70 6f 72 74 61 6e 74 20 6e 6f  .<b>Important no
0b30: 74 69 63 65 3c 2f 62 3e 3a 20 74 68 65 20 76 65  tice</b>: the ve
0b40: 72 79 20 72 65 63 65 6e 74 20 53 51 4c 69 74 65  ry recent SQLite
0b50: 20 3c 62 3e 33 2e 37 2e 31 37 3c 2f 62 3e 20 69   <b>3.7.17</b> i
0b60: 6e 74 72 6f 64 75 63 65 64 20 6d 61 6e 79 20 69  ntroduced many i
0b70: 6e 74 65 72 65 73 74 69 6e 67 20 61 64 76 61 6e  nteresting advan
0b80: 63 65 64 20 66 65 61 74 75 72 65 73 20 74 6f 20  ced features to 
0b90: 3c 62 3e 6c 6f 61 64 5f 65 78 74 65 6e 73 69 6f  <b>load_extensio
0ba0: 6e 28 29 3c 2f 62 3e 3b 0d 0a 65 61 72 6c 69 65  n()</b>;..earlie
0bb0: 72 20 76 65 72 73 69 6f 6e 73 20 6f 66 20 53 51  r versions of SQ
0bc0: 4c 69 74 65 20 63 6f 75 6c 64 20 70 72 6f 62 61  Lite could proba
0bd0: 62 6c 79 20 62 65 20 73 6f 6d 65 77 61 79 20 6c  bly be someway l
0be0: 69 6d 69 74 65 64 2e 0d 0a 49 66 20 74 68 69 73  imited...If this
0bf0: 20 69 73 20 79 6f 75 72 20 63 61 73 65 2c 20 70   is your case, p
0c00: 6c 65 61 73 65 20 63 6f 6e 73 69 64 65 72 20 74  lease consider t
0c10: 68 61 74 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e  hat:..<ul>..<li>
0c20: 73 70 65 63 69 66 79 69 6e 67 20 61 6e 79 20 3c  specifying any <
0c30: 62 3e 2e 64 6c 6c 3c 2f 62 3e 2c 20 3c 62 3e 2e  b>.dll</b>, <b>.
0c40: 73 6f 3c 2f 62 3e 20 6f 72 20 3c 62 3e 2e 64 79  so</b> or <b>.dy
0c50: 6c 69 62 3c 2f 62 3e 20 73 75 66 66 69 78 20 63  lib</b> suffix c
0c60: 6f 75 6c 64 20 62 65 20 73 74 72 69 63 74 6c 79  ould be strictly
0c70: 20 72 65 71 75 69 72 65 64 2e 3c 2f 6c 69 3e 0d   required.</li>.
0c80: 0a 3c 6c 69 3e 61 73 20 69 74 20 63 6f 75 6c 64  .<li>as it could
0c90: 20 62 65 20 72 65 71 75 69 72 65 64 20 74 6f 20   be required to 
0ca0: 65 78 70 6c 69 63 69 74 6c 79 20 73 70 65 63 69  explicitly speci
0cb0: 66 79 20 74 68 65 20 65 78 74 65 6e 73 69 6f 6e  fy the extension
0cc0: 20 65 6e 74 72 79 20 70 6f 69 6e 74 2e 3c 2f 6c   entry point.</l
0cd0: 69 3e 0d 0a 3c 6c 69 3e 61 63 63 6f 72 64 69 6e  i>..<li>accordin
0ce0: 67 6c 79 20 74 6f 20 61 6c 6c 20 74 68 69 73 2c  gly to all this,
0cf0: 20 79 6f 75 27 6c 6c 20 70 72 6f 62 61 62 6c 79   you'll probably
0d00: 20 62 65 20 72 65 71 75 69 72 65 64 20 74 6f 20   be required to 
0d10: 70 61 73 73 20 61 72 67 75 6d 65 6e 74 73 20 6c  pass arguments l
0d20: 69 6b 65 20 74 6f 20 66 6f 6c 6c 6f 77 69 6e 67  ike to following
0d30: 20 6f 6e 65 73 20 74 6f 20 3c 62 3e 6c 6f 61 64   ones to <b>load
0d40: 5f 65 78 74 65 6e 73 69 6f 6e 28 29 3c 2f 62 3e  _extension()</b>
0d50: 20 77 68 69 6c 65 20 75 73 69 6e 67 20 73 6f 6d   while using som
0d60: 65 20 6f 62 73 6f 6c 65 74 65 20 53 51 4c 69 74  e obsolete SQLit
0d70: 65 33 20 76 65 72 73 69 6f 6e 2e 3c 2f 6c 69 3e  e3 version.</li>
0d80: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45  ..<verbatim>..SE
0d90: 4c 45 43 54 20 6c 6f 61 64 5f 65 78 74 65 6e 73  LECT load_extens
0da0: 69 6f 6e 28 27 2f 75 73 72 2f 6c 6f 63 61 6c 2f  ion('/usr/local/
0db0: 6c 69 62 2f 6c 69 62 76 69 72 74 75 61 6c 70 67  lib/libvirtualpg
0dc0: 2e 73 6f 27 2c 20 27 73 71 6c 69 74 65 33 5f 76  .so', 'sqlite3_v
0dd0: 69 72 74 75 61 6c 70 67 5f 69 6e 69 74 27 29 3b  irtualpg_init');
0de0: 0d 0a 2d 2d 2d 2d 2d 2d 0d 0a 4e 55 4c 4c 0d 0a  ..------..NULL..
0df0: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 3c 2f 75  </verbatim>..</u
0e00: 6c 3e 0d 0a 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a  l>..</td></tr>..
0e10: 3c 2f 74 61 62 6c 65 3e 3c 62 72 3e 0d 0a 3c 68  </table><br>..<h
0e20: 72 3e 0d 0a 3c 68 33 3e 63 72 6f 73 73 2d 44 42  r>..<h3>cross-DB
0e30: 4d 53 20 64 61 74 61 20 65 78 63 68 61 6e 67 65  MS data exchange
0e40: 3a 20 53 51 4c 20 61 6e 64 20 56 69 72 74 75 61  : SQL and Virtua
0e50: 6c 50 6f 73 74 67 72 65 73 20 74 61 62 6c 65 73  lPostgres tables
0e60: 3c 2f 68 33 3e 0d 0a 41 66 74 65 72 20 73 75 63  </h3>..After suc
0e70: 63 65 73 73 66 75 6c 6c 79 20 6c 6f 61 64 69 6e  cessfully loadin
0e80: 67 20 74 68 65 20 3c 62 3e 76 69 72 74 75 61 6c  g the <b>virtual
0e90: 70 67 3c 2f 62 3e 20 64 79 6e 61 6d 69 63 20 65  pg</b> dynamic e
0ea0: 78 74 65 6e 73 69 6f 6e 20 79 6f 75 20 61 72 65  xtension you are
0eb0: 20 6e 6f 77 20 72 65 61 64 79 20 74 6f 20 63 72   now ready to cr
0ec0: 65 61 74 65 20 3c 62 3e 56 69 72 74 75 61 6c 50  eate <b>VirtualP
0ed0: 6f 73 74 67 65 73 3c 2f 62 3e 20 74 61 62 6c 65  ostges</b> table
0ee0: 73 2e 3c 62 72 3e 0d 0a 54 68 65 73 65 20 61 72  s.<br>..These ar
0ef0: 65 20 3c 69 3e 71 75 69 74 65 20 61 6c 6d 6f 73  e <i>quite almos
0f00: 74 3c 2f 69 3e 20 6f 72 64 69 6e 61 72 79 20 44  t</i> ordinary D
0f10: 42 20 74 61 62 6c 65 73 20 61 73 20 61 6e 79 20  B tables as any 
0f20: 6f 74 68 65 72 3b 20 79 6f 75 20 63 61 6e 20 65  other; you can e
0f30: 78 65 63 75 74 65 20 61 6e 79 20 72 65 67 75 6c  xecute any regul
0f40: 61 72 20 53 51 4c 20 73 74 61 74 65 6d 65 6e 74  ar SQL statement
0f50: 20 28 3c 69 3e 53 45 4c 45 43 54 3c 2f 69 3e 2c   (<i>SELECT</i>,
0f60: 20 3c 69 3e 49 4e 53 45 52 54 3c 2f 69 3e 2c 20   <i>INSERT</i>, 
0f70: 3c 69 3e 55 50 44 41 54 45 3c 2f 69 3e 20 6f 72  <i>UPDATE</i> or
0f80: 20 3c 69 3e 44 45 4c 45 54 45 3c 2f 69 3e 29 20   <i>DELETE</i>) 
0f90: 62 79 20 73 70 65 63 69 66 79 69 6e 67 20 74 68  by specifying th
0fa0: 65 73 65 20 56 69 72 74 75 61 6c 20 54 61 62 6c  ese Virtual Tabl
0fb0: 65 73 20 61 73 20 74 68 65 20 73 65 6c 65 63 74  es as the select
0fc0: 65 64 20 74 61 72 67 65 74 2e 3c 62 72 3e 0d 0a  ed target.<br>..
0fd0: 54 68 65 72 65 20 69 73 20 6f 6e 6c 79 20 61 20  There is only a 
0fe0: 73 74 72 6f 6e 67 20 64 69 66 66 65 72 65 6e 63  strong differenc
0ff0: 65 20 64 69 73 74 69 6e 67 75 69 73 68 69 6e 67  e distinguishing
1000: 20 61 20 3c 62 3e 56 69 72 74 75 61 6c 50 6f 73   a <b>VirtualPos
1010: 74 67 72 65 73 3c 2f 62 3e 20 74 61 62 6c 65 3b  tgres</b> table;
1020: 20 69 74 27 73 20 70 68 79 73 69 63 61 6c 20 6c   it's physical l
1030: 6f 63 61 74 69 6f 6e 20 69 73 6e 27 74 20 77 69  ocation isn't wi
1040: 74 68 69 6e 20 74 68 65 20 63 75 72 72 65 6e 74  thin the current
1050: 6c 79 20 63 6f 6e 6e 65 63 74 65 64 20 53 51 4c  ly connected SQL
1060: 69 74 65 20 44 42 2c 20 62 75 74 20 69 73 20 69  ite DB, but is i
1070: 6e 73 74 65 61 64 20 77 69 74 68 69 6e 20 73 6f  nstead within so
1080: 6d 65 20 3c 62 3e 50 6f 73 74 67 72 65 53 51 4c  me <b>PostgreSQL
1090: 3c 2f 62 3e 20 44 42 4d 53 2e 3c 62 72 3e 0d 0a  </b> DBMS.<br>..
10a0: 53 6f 20 61 20 56 69 72 74 75 61 6c 50 6f 73 74  So a VirtualPost
10b0: 67 72 65 73 20 74 61 62 6c 65 20 65 66 66 65 63  gres table effec
10c0: 74 69 76 65 6c 79 20 61 63 74 73 20 61 73 20 61  tively acts as a
10d0: 20 3c 69 3e 62 72 69 64 67 65 3c 2f 69 3e 20 6a   <i>bridge</i> j
10e0: 6f 69 6e 69 6e 67 20 53 51 4c 69 74 65 20 61 6e  oining SQLite an
10f0: 64 20 50 6f 73 74 67 72 65 73 2c 20 61 6e 64 20  d Postgres, and 
1100: 61 6c 6c 6f 77 69 6e 67 20 74 6f 20 70 65 72 66  allowing to perf
1110: 6f 72 6d 20 61 6e 79 20 6b 69 6e 64 20 6f 66 20  orm any kind of 
1120: 63 72 6f 73 73 20 64 61 74 61 20 65 78 63 68 61  cross data excha
1130: 6e 67 65 20 28 3c 69 3e 69 6e 20 62 6f 74 68 20  nge (<i>in both 
1140: 64 69 72 65 63 74 69 6f 6e 73 3c 2f 69 3e 29 20  directions</i>) 
1150: 69 6e 20 74 68 65 20 65 61 73 69 65 73 74 20 77  in the easiest w
1160: 61 79 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d  ay...<verbatim>.
1170: 0a 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20  .CREATE VIRTUAL 
1180: 54 41 42 4c 45 20 70 67 5f 69 6e 20 0d 0a 20 20  TABLE pg_in ..  
1190: 20 20 55 53 49 4e 47 20 56 69 72 74 75 61 6c 50    USING VirtualP
11a0: 6f 73 74 67 72 65 73 20 28 27 68 6f 73 74 3d 6c  ostgres ('host=l
11b0: 6f 63 61 6c 68 6f 73 74 20 70 6f 72 74 3d 35 34  ocalhost port=54
11c0: 33 32 20 64 62 6e 61 6d 65 3d 67 69 73 20 75 73  32 dbname=gis us
11d0: 65 72 3d 73 61 6e 64 72 6f 20 70 61 73 73 77 6f  er=sandro passwo
11e0: 72 64 3d 73 65 63 72 65 74 27 2c 20 6d 79 5f 73  rd=secret', my_s
11f0: 63 68 65 6d 61 2c 20 6d 79 5f 74 61 62 6c 65 29  chema, my_table)
1200: 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a  ;..</verbatim>..
1210: 54 68 69 73 20 53 51 4c 20 73 74 61 74 65 6d 65  This SQL stateme
1220: 6e 74 20 77 69 6c 6c 20 63 72 65 61 74 65 20 69  nt will create i
1230: 6e 74 6f 20 74 68 65 20 53 51 4c 69 74 65 20 44  nto the SQLite D
1240: 42 20 61 20 74 61 62 6c 65 20 6e 61 6d 65 64 20  B a table named 
1250: 3c 62 3e 70 67 5f 69 6e 3c 2f 62 3e 3b 20 61 6e  <b>pg_in</b>; an
1260: 79 77 61 79 20 74 68 65 20 64 61 74 61 20 70 68  yway the data ph
1270: 79 73 69 63 61 6c 20 73 74 6f 72 61 67 65 20 66  ysical storage f
1280: 6f 72 20 74 68 69 73 20 74 61 62 6c 65 20 77 69  or this table wi
1290: 6c 6c 20 62 65 20 69 6e 74 6f 20 74 68 65 20 50  ll be into the P
12a0: 6f 73 74 67 72 65 73 20 44 42 4d 53 3a 0d 0a 3c  ostgres DBMS:..<
12b0: 75 6c 3e 0d 0a 3c 6c 69 3e 74 68 65 20 66 69 72  ul>..<li>the fir
12c0: 73 74 20 61 72 67 75 6d 65 6e 74 20 74 6f 20 56  st argument to V
12d0: 69 72 74 75 61 6c 50 6f 73 74 67 72 65 73 20 69  irtualPostgres i
12e0: 73 20 74 68 65 20 3c 69 3e 63 6f 6e 6e 65 63 74  s the <i>connect
12f0: 69 6f 6e 20 73 74 72 69 6e 67 3c 2f 69 3e 20 72  ion string</i> r
1300: 65 71 75 69 72 65 64 20 69 6e 20 6f 72 64 65 72  equired in order
1310: 20 74 6f 20 65 73 74 61 62 6c 69 73 68 20 61 20   to establish a 
1320: 63 6f 6e 6e 65 63 74 69 6f 6e 20 74 6f 20 74 68  connection to th
1330: 65 20 50 6f 73 74 67 72 65 73 20 44 42 4d 53 20  e Postgres DBMS 
1340: 73 65 72 76 65 72 2e 3c 2f 6c 69 3e 0d 0a 3c 6c  server.</li>..<l
1350: 69 3e 73 65 63 6f 6e 64 20 61 6e 64 20 74 68 69  i>second and thi
1360: 72 64 20 61 72 67 75 6d 65 6e 74 73 20 72 65 73  rd arguments res
1370: 70 65 63 74 69 76 65 6c 79 20 61 72 65 20 74 68  pectively are th
1380: 65 20 3c 69 3e 73 63 68 65 6d 61 20 6e 61 6d 65  e <i>schema name
1390: 3c 2f 69 3e 20 61 6e 64 20 74 68 65 20 3c 69 3e  </i> and the <i>
13a0: 74 61 62 6c 65 20 6e 61 6d 65 3c 2f 69 3e 20 69  table name</i> i
13b0: 64 65 6e 74 69 66 79 69 6e 67 20 74 68 65 20 50  dentifying the P
13c0: 6f 73 74 67 72 65 73 20 74 61 72 67 65 74 20 74  ostgres target t
13d0: 61 62 6c 65 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c  able.</li>..</ul
13e0: 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 43  >..<verbatim>..C
13f0: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41  REATE VIRTUAL TA
1400: 42 4c 45 20 70 67 5f 69 6e 20 0d 0a 20 20 20 20  BLE pg_in ..    
1410: 55 53 49 4e 47 20 56 69 72 74 75 61 6c 50 6f 73  USING VirtualPos
1420: 74 67 72 65 73 20 28 27 68 6f 73 74 61 64 64 72  tgres ('hostaddr
1430: 3d 31 39 32 2e 31 36 38 2e 31 2e 39 31 20 70 6f  =192.168.1.91 po
1440: 72 74 3d 35 34 33 32 20 64 62 6e 61 6d 65 3d 67  rt=5432 dbname=g
1450: 69 73 20 75 73 65 72 3d 73 61 6e 64 72 6f 20 70  is user=sandro p
1460: 61 73 73 77 6f 72 64 3d 73 65 63 72 65 74 27 2c  assword=secret',
1470: 20 6d 79 5f 73 63 68 65 6d 61 2c 20 6d 79 5f 74   my_schema, my_t
1480: 61 62 6c 65 29 3b 0d 0a 3c 2f 76 65 72 62 61 74  able);..</verbat
1490: 69 6d 3e 0d 0a 53 61 6d 65 20 61 73 20 61 62 6f  im>..Same as abo
14a0: 76 65 2c 20 74 68 65 20 74 69 6d 65 20 65 73 74  ve, the time est
14b0: 61 62 6c 69 73 68 69 6e 67 20 61 20 63 6f 6e 6e  ablishing a conn
14c0: 65 63 74 69 6f 6e 20 74 6f 20 61 20 50 6f 73 74  ection to a Post
14d0: 67 72 65 73 20 69 6e 73 74 61 6e 63 65 20 72 75  gres instance ru
14e0: 6e 6e 69 6e 67 20 6f 6e 20 73 6f 6d 65 20 64 69  nning on some di
14f0: 66 66 65 72 65 6e 74 20 63 6f 6d 70 75 74 65 72  fferent computer
1500: 20 6f 6e 20 74 68 65 20 73 61 6d 65 20 6c 6f 63   on the same loc
1510: 61 6c 20 61 72 65 61 20 6e 65 74 77 6f 72 6b 2e  al area network.
1520: 3c 62 72 3e 0d 0a 50 6c 65 61 73 65 20 63 6f 6e  <br>..Please con
1530: 73 75 6c 74 20 74 68 65 20 50 6f 73 74 67 72 65  sult the Postgre
1540: 73 20 6f 77 6e 20 64 6f 63 75 6d 65 6e 74 61 74  s own documentat
1550: 69 6f 6e 20 66 6f 72 20 61 6e 79 20 6f 74 68 65  ion for any othe
1560: 72 20 64 65 74 61 69 6c 20 61 62 6f 75 74 20 3c  r detail about <
1570: 69 3e 63 6f 6e 6e 65 63 74 69 6f 6e 20 73 74 72  i>connection str
1580: 69 6e 67 73 3c 2f 69 3e 2e 0d 0a 3c 76 65 72 62  ings</i>...<verb
1590: 61 74 69 6d 3e 0d 0a 50 52 41 47 4d 41 20 74 61  atim>..PRAGMA ta
15a0: 62 6c 65 5f 69 6e 66 6f 28 70 67 5f 69 6e 29 3b  ble_info(pg_in);
15b0: 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 59  ..</verbatim>..Y
15c0: 6f 75 20 63 61 6e 20 65 78 65 63 75 74 65 20 74  ou can execute t
15d0: 68 65 20 61 62 6f 76 65 20 50 52 41 47 4d 41 20  he above PRAGMA 
15e0: 64 69 72 65 63 74 69 76 65 20 69 6e 20 6f 72 64  directive in ord
15f0: 65 72 20 74 6f 20 69 64 65 6e 74 69 66 79 20 61  er to identify a
1600: 6c 6c 20 63 6f 6c 75 6d 6e 73 20 64 65 63 6c 61  ll columns decla
1610: 72 65 64 20 62 79 20 74 68 65 20 50 6f 73 74 67  red by the Postg
1620: 72 65 73 20 74 61 62 6c 65 2c 20 61 6e 64 20 74  res table, and t
1630: 68 65 69 72 20 63 6f 72 72 65 73 70 6f 6e 64 69  heir correspondi
1640: 6e 67 20 64 61 74 61 2d 74 79 70 65 2e 3c 62 72  ng data-type.<br
1650: 3e 0d 0a 49 66 20 79 6f 75 20 61 72 65 20 61 63  >..If you are ac
1660: 74 75 61 6c 6c 79 20 75 73 69 6e 67 20 3c 62 3e  tually using <b>
1670: 73 70 61 74 69 61 6c 69 74 65 5f 67 75 69 3c 2f  spatialite_gui</
1680: 62 3e 20 79 6f 75 20 63 61 6e 20 63 68 65 63 6b  b> you can check
1690: 20 74 68 65 20 73 61 6d 65 20 69 6e 66 6f 73 20   the same infos 
16a0: 62 79 20 75 73 69 6e 67 20 74 68 65 20 61 70 70  by using the app
16b0: 72 6f 70 72 69 61 74 65 20 67 72 61 70 68 69 63  ropriate graphic
16c0: 73 20 74 6f 6f 6c 73 2e 0d 0a 3c 76 65 72 62 61  s tools...<verba
16d0: 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 61 2c 20  tim>..SELECT a, 
16e0: 62 2c 20 63 2c 20 43 6f 75 6e 74 28 2a 29 20 41  b, c, Count(*) A
16f0: 53 20 63 6e 74 0d 0a 46 52 4f 4d 20 70 67 5f 69  S cnt..FROM pg_i
1700: 6e 0d 0a 57 48 45 52 45 20 65 20 49 53 20 4e 4f  n..WHERE e IS NO
1710: 54 20 4e 55 4c 4c 0d 0a 47 52 4f 55 50 20 42 59  T NULL..GROUP BY
1720: 20 61 2c 20 62 2c 20 63 0d 0a 4f 52 44 45 52 20   a, b, c..ORDER 
1730: 42 59 20 63 6e 74 20 44 45 53 43 3b 0d 0a 3c 2f  BY cnt DESC;..</
1740: 76 65 72 62 61 74 69 6d 3e 0d 0a 59 6f 75 20 63  verbatim>..You c
1750: 61 6e 20 65 78 65 63 75 74 65 20 61 6e 79 20 6b  an execute any k
1760: 69 6e 64 20 6f 66 20 3c 62 3e 53 45 4c 45 43 54  ind of <b>SELECT
1770: 3c 2f 62 3e 20 71 75 65 72 79 20 75 73 69 6e 67  </b> query using
1780: 20 61 20 56 69 72 74 75 61 6c 50 6f 73 74 67 72   a VirtualPostgr
1790: 65 73 20 74 61 62 6c 65 2c 20 65 78 61 63 74 6c  es table, exactl
17a0: 79 20 61 73 20 69 66 20 69 74 20 77 61 73 20 61  y as if it was a
17b0: 20 67 65 6e 75 69 6e 65 20 6e 61 74 69 76 65 20   genuine native 
17c0: 74 61 62 6c 65 2e 0d 0a 3c 76 65 72 62 61 74 69  table...<verbati
17d0: 6d 3e 0d 0a 43 52 45 41 54 45 20 54 41 42 4c 45  m>..CREATE TABLE
17e0: 20 69 6d 70 6f 72 74 65 64 5f 66 72 6f 6d 5f 70   imported_from_p
17f0: 67 20 41 53 0d 0a 53 45 4c 45 43 54 20 2a 20 46  g AS..SELECT * F
1800: 52 4f 4d 20 70 67 5f 69 6e 3b 0d 0a 3c 2f 76 65  ROM pg_in;..</ve
1810: 72 62 61 74 69 6d 3e 0d 0a 41 6e 64 20 79 6f 75  rbatim>..And you
1820: 20 63 61 6e 20 6f 62 76 69 6f 75 73 6c 79 20 63   can obviously c
1830: 72 65 61 74 65 20 61 6e 64 20 70 6f 70 75 6c 61  reate and popula
1840: 74 65 20 61 20 6c 6f 63 61 6c 20 63 6f 70 79 20  te a local copy 
1850: 6f 66 20 74 68 65 20 72 65 6d 6f 74 65 20 50 6f  of the remote Po
1860: 73 74 67 72 65 73 20 74 61 62 6c 65 3a 20 6e 6f  stgres table: no
1870: 77 20 61 6c 6c 20 64 61 74 61 20 61 72 65 20 70  w all data are p
1880: 65 72 6d 61 6e 65 6e 74 6c 79 20 73 74 6f 72 65  ermanently store
1890: 64 20 77 69 74 68 69 6e 20 79 6f 75 72 20 53 51  d within your SQ
18a0: 4c 69 74 65 20 44 42 2e 0d 0a 3c 76 65 72 62 61  Lite DB...<verba
18b0: 74 69 6d 3e 0d 0a 44 52 4f 50 20 54 41 42 4c 45  tim>..DROP TABLE
18c0: 20 70 67 5f 69 6e 3b 0d 0a 3c 2f 76 65 72 62 61   pg_in;..</verba
18d0: 74 69 6d 3e 0d 0a 53 6f 20 79 6f 75 20 63 61 6e  tim>..So you can
18e0: 20 66 69 6e 61 6c 6c 79 20 64 72 6f 70 20 74 68   finally drop th
18f0: 65 20 56 69 72 74 75 61 6c 50 6f 73 74 67 72 65  e VirtualPostgre
1900: 73 20 74 61 62 6c 65 2c 20 61 6e 64 20 74 68 69  s table, and thi
1910: 73 20 77 69 6c 6c 20 69 6d 6d 65 64 69 61 74 65  s will immediate
1920: 6c 79 20 74 65 72 6d 69 6e 61 74 65 20 74 68 65  ly terminate the
1930: 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 74 6f 20 74   connection to t
1940: 68 65 20 50 6f 73 74 67 72 65 73 20 44 42 4d 53  he Postgres DBMS
1950: 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d  .<br><br>..<hr>.
1960: 0a 3c 68 33 3e 64 61 74 61 2d 74 79 70 65 20 6d  .<h3>data-type m
1970: 61 70 70 69 6e 67 20 61 6e 64 20 72 65 6c 61 74  apping and relat
1980: 65 64 20 63 6f 6e 76 65 72 73 69 6f 6e 73 3c 2f  ed conversions</
1990: 68 33 3e 0d 0a 52 61 74 68 65 72 20 6f 62 76 69  h3>..Rather obvi
19a0: 6f 75 73 6c 79 20 53 51 4c 69 74 65 20 61 6e 64  ously SQLite and
19b0: 20 50 6f 73 74 67 72 65 73 20 73 75 70 70 6f 72   Postgres suppor
19c0: 74 73 20 76 65 72 79 20 64 69 66 66 65 72 65 6e  ts very differen
19d0: 74 20 6b 69 6e 64 20 6f 66 20 64 61 74 61 2d 74  t kind of data-t
19e0: 79 70 65 73 2e 20 54 68 65 20 66 65 77 20 66 6f  ypes. The few fo
19f0: 6c 6c 6f 77 69 6e 67 20 72 75 6c 65 73 20 61 70  llowing rules ap
1a00: 70 6c 79 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e  ply:..<ul>..<li>
1a10: 61 6e 79 20 6b 69 6e 64 20 6f 66 20 3c 62 3e 49  any kind of <b>I
1a20: 4e 54 45 47 45 52 3c 2f 62 3e 20 76 61 6c 75 65  NTEGER</b> value
1a30: 20 69 73 20 70 72 65 73 65 72 76 65 64 20 61 73   is preserved as
1a40: 20 73 75 63 68 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69   such.</li>..<li
1a50: 3e 74 68 65 20 73 61 6d 65 20 69 73 20 66 6f 72  >the same is for
1a60: 20 3c 62 3e 46 4c 4f 41 54 3c 2f 62 3e 20 76 61   <b>FLOAT</b> va
1a70: 6c 75 65 73 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e  lues.</li>..<li>
1a80: 3c 62 3e 4d 4f 4e 45 59 3c 2f 62 3e 20 61 6e 64  <b>MONEY</b> and
1a90: 20 3c 62 3e 4e 55 4d 45 52 49 43 3c 2f 62 3e 20   <b>NUMERIC</b> 
1aa0: 76 61 6c 75 65 73 20 61 72 65 20 63 6f 6e 76 65  values are conve
1ab0: 72 74 65 64 20 69 6e 74 6f 20 3c 62 3e 46 4c 4f  rted into <b>FLO
1ac0: 41 54 3c 2f 62 3e 20 76 61 6c 75 65 73 2e 3c 2f  AT</b> values.</
1ad0: 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 43 48 41 52  li>..<li><b>CHAR
1ae0: 3c 2f 62 3e 20 61 6e 64 20 3c 62 3e 56 41 52 43  </b> and <b>VARC
1af0: 48 41 52 3c 2f 62 3e 20 76 61 6c 75 65 73 20 61  HAR</b> values a
1b00: 72 65 20 61 6c 77 61 79 73 20 63 6f 6e 76 65 72  re always conver
1b10: 74 65 64 20 69 6e 74 6f 20 3c 62 3e 54 45 58 54  ted into <b>TEXT
1b20: 3c 2f 62 3e 20 76 61 6c 75 65 73 2e 3c 2f 6c 69  </b> values.</li
1b30: 3e 0d 0a 3c 6c 69 3e 3c 62 3e 44 41 54 45 3c 2f  >..<li><b>DATE</
1b40: 62 3e 2c 20 3c 62 3e 54 49 4d 45 3c 2f 62 3e 20  b>, <b>TIME</b> 
1b50: 61 6e 64 20 3c 62 3e 54 49 4d 45 53 54 41 4d 50  and <b>TIMESTAMP
1b60: 3c 2f 62 3e 20 76 61 6c 75 65 73 20 61 72 65 20  </b> values are 
1b70: 61 6c 77 61 79 73 20 63 6f 6e 76 65 72 74 65 64  always converted
1b80: 20 69 6e 74 6f 20 3c 62 3e 46 4c 4f 41 54 3c 2f   into <b>FLOAT</
1b90: 62 3e 20 76 61 6c 75 65 73 20 63 6f 72 72 65 73  b> values corres
1ba0: 70 6f 6e 64 69 6e 67 20 74 6f 20 74 68 65 20 3c  ponding to the <
1bb0: 61 20 68 72 65 66 3d 22 68 74 74 70 3a 2f 2f 77  a href="http://w
1bc0: 77 77 2e 73 71 6c 69 74 65 2e 6f 72 67 2f 6c 61  ww.sqlite.org/la
1bd0: 6e 67 5f 64 61 74 65 66 75 6e 63 2e 68 74 6d 6c  ng_datefunc.html
1be0: 22 3e 4a 75 6c 69 61 6e 44 61 79 3c 2f 61 3e 20  ">JulianDay</a> 
1bf0: 6e 6f 74 61 74 69 6f 6e 20 73 75 70 70 6f 72 74  notation support
1c00: 65 64 20 62 79 20 53 51 4c 69 74 65 2e 3c 62 72  ed by SQLite.<br
1c10: 3e 0d 0a 59 6f 75 20 63 61 6e 20 74 68 65 6e 20  >..You can then 
1c20: 69 6e 76 6f 6b 65 20 74 68 65 20 61 70 70 72 6f  invoke the appro
1c30: 70 72 69 61 74 65 20 66 75 6e 63 74 69 6f 6e 20  priate function 
1c40: 62 65 74 77 65 65 6e 20 3c 62 3e 44 61 74 65 28  between <b>Date(
1c50: 29 3c 2f 62 3e 2c 20 3c 62 3e 54 69 6d 65 28 29  )</b>, <b>Time()
1c60: 3c 2f 62 3e 20 6f 72 20 3c 62 3e 44 61 74 65 54  </b> or <b>DateT
1c70: 69 6d 65 28 29 3c 2f 62 3e 20 73 6f 20 74 6f 20  ime()</b> so to 
1c80: 67 65 74 20 62 61 63 6b 20 74 68 65 20 73 74 61  get back the sta
1c90: 6e 64 61 72 64 20 53 51 4c 20 6e 6f 74 61 74 69  ndard SQL notati
1ca0: 6f 6e 20 66 6f 72 20 64 61 74 65 73 20 61 6e 64  on for dates and
1cb0: 20 74 69 6d 65 73 2e 3c 2f 6c 69 3e 0d 0a 3c 6c   times.</li>..<l
1cc0: 69 3e 3c 62 3e 42 4f 4f 4c 3c 2f 62 3e 20 76 61  i><b>BOOL</b> va
1cd0: 6c 75 65 73 20 61 72 65 20 61 6c 77 61 79 73 20  lues are always 
1ce0: 63 6f 6e 76 65 72 74 65 64 20 69 6e 74 6f 20 3c  converted into <
1cf0: 62 3e 49 4e 54 45 47 45 52 3c 2f 62 3e 20 76 61  b>INTEGER</b> va
1d00: 6c 75 65 73 3a 20 3c 62 3e 30 3c 2f 62 3e 20 63  lues: <b>0</b> c
1d10: 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 74 6f 20  orresponding to 
1d20: 3c 62 3e 46 41 4c 53 45 3c 2f 62 3e 2e 3c 2f 6c  <b>FALSE</b>.</l
1d30: 69 3e 0d 0a 3c 6c 69 3e 50 6f 73 74 67 72 65 73  i>..<li>Postgres
1d40: 20 73 75 70 70 6f 72 74 73 20 6d 75 6c 74 69 70   supports multip
1d50: 6c 65 20 76 61 6c 75 65 73 20 74 6f 20 62 65 20  le values to be 
1d60: 73 74 6f 72 65 64 20 69 6e 74 6f 20 74 68 65 20  stored into the 
1d70: 73 61 6d 65 20 63 6f 6c 75 6d 6e 20 28 3c 62 3e  same column (<b>
1d80: 41 52 52 41 59 3c 2f 62 3e 29 3a 20 53 51 4c 69  ARRAY</b>): SQLi
1d90: 74 65 20 68 61 73 20 6e 6f 20 73 69 6d 69 6c 61  te has no simila
1da0: 72 20 63 61 70 61 62 69 6c 69 74 79 2c 20 73 6f  r capability, so
1db0: 20 61 6e 79 20 41 52 52 41 59 20 76 61 6c 75 65   any ARRAY value
1dc0: 20 77 69 6c 6c 20 73 69 6d 70 6c 79 20 62 65 20   will simply be 
1dd0: 63 6f 6e 76 65 72 74 65 64 20 69 6e 74 6f 20 61  converted into a
1de0: 20 3c 62 3e 54 45 58 54 3c 2f 62 3e 20 73 74 72   <b>TEXT</b> str
1df0: 69 6e 67 2c 20 65 2e 67 2e 20 61 73 20 69 6e 20  ing, e.g. as in 
1e00: 3c 62 3e 27 7b 31 2c 32 2c 33 7d 27 3c 2f 62 3e  <b>'{1,2,3}'</b>
1e10: 20 6f 72 20 3c 62 3e 27 7b 61 6c 70 68 61 2c 62   or <b>'{alpha,b
1e20: 65 74 61 2c 67 61 6d 6d 61 2c 64 65 6c 74 61 7d  eta,gamma,delta}
1e30: 27 3c 2f 62 3e 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69  '</b>.</li>..<li
1e40: 3e 61 6e 79 20 62 69 6e 61 72 79 20 76 61 6c 75  >any binary valu
1e50: 65 20 28 61 73 20 65 2e 67 2e 20 3c 62 3e 42 59  e (as e.g. <b>BY
1e60: 54 45 41 3c 2f 62 3e 29 20 77 69 6c 6c 20 62 65  TEA</b>) will be
1e70: 20 73 69 6d 70 6c 79 20 63 6f 6e 76 65 72 74 65   simply converte
1e80: 64 20 69 6e 74 6f 20 61 20 3c 62 3e 54 45 58 54  d into a <b>TEXT
1e90: 3c 2f 62 3e 20 76 61 6c 75 65 20 63 6f 6e 74 61  </b> value conta
1ea0: 69 6e 69 6e 67 20 74 68 65 20 63 6f 72 72 65 73  ining the corres
1eb0: 70 6f 6e 64 69 6e 67 20 68 65 78 61 64 65 63 69  ponding hexadeci
1ec0: 6d 61 6c 20 6e 6f 74 61 74 69 6f 6e 2c 20 65 2e  mal notation, e.
1ed0: 67 2e 20 61 73 20 69 6e 20 3c 62 3e 27 30 31 30  g. as in <b>'010
1ee0: 31 30 30 30 30 32 30 45 38 36 34 30 30 30 30 43  1000020E8640000C
1ef0: 34 46 43 33 34 42 41 38 34 34 38 32 34 34 31 35  4FC34BA844824415
1f00: 30 43 31 42 35 44 35 34 31 42 38 35 33 34 31 27  0C1B5D541B85341'
1f10: 3c 2f 62 3e 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c  </b>.</li>..</ul
1f20: 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c 68 33  ><br>..<hr>..<h3
1f30: 3e 68 61 6e 64 6c 69 6e 67 20 50 6f 73 74 47 49  >handling PostGI
1f40: 53 20 67 65 6f 6d 65 74 72 69 65 73 3c 2f 68 33  S geometries</h3
1f50: 3e 0d 0a 50 6f 73 74 47 49 53 20 6f 77 6e 20 67  >..PostGIS own g
1f60: 65 6f 6d 65 74 72 69 65 73 20 73 69 6d 70 6c 79  eometries simply
1f70: 20 61 72 65 20 72 65 70 72 65 73 65 6e 74 65 64   are represented
1f80: 20 62 79 20 61 20 3c 62 3e 42 59 54 45 41 3c 2f   by a <b>BYTEA</
1f90: 62 3e 20 76 61 6c 75 65 20 74 6f 20 62 65 20 69  b> value to be i
1fa0: 6e 74 65 72 70 72 65 74 65 64 20 61 63 63 6f 72  nterpreted accor
1fb0: 64 69 6e 67 6c 79 20 74 6f 20 3c 62 3e 45 57 4b  dingly to <b>EWK
1fc0: 42 3c 2f 62 3e 20 66 6f 72 6d 61 74 20 73 70 65  B</b> format spe
1fd0: 63 69 66 69 63 61 74 69 6f 6e 73 2e 0d 0a 3c 76  cifications...<v
1fe0: 65 72 62 61 74 69 6d 3e 0d 0a 43 52 45 41 54 45  erbatim>..CREATE
1ff0: 20 54 41 42 4c 45 20 66 72 6f 6d 5f 70 6f 73 74   TABLE from_post
2000: 67 69 73 20 41 53 0d 0a 53 45 4c 45 43 54 20 2a  gis AS..SELECT *
2010: 20 46 52 4f 4d 20 70 67 5f 69 6e 3b 0d 0a 0d 0a   FROM pg_in;....
2020: 55 50 44 41 54 45 20 66 72 6f 6d 5f 70 6f 73 74  UPDATE from_post
2030: 67 69 73 20 53 45 54 20 67 65 6f 6d 65 74 72 79  gis SET geometry
2040: 20 3d 20 47 65 6f 6d 46 72 6f 6d 45 57 4b 42 28   = GeomFromEWKB(
2050: 67 65 6f 6d 65 74 72 79 29 3b 0d 0a 0d 0a 53 45  geometry);....SE
2060: 4c 45 43 54 20 44 49 53 54 49 4e 43 54 20 53 54  LECT DISTINCT ST
2070: 5f 47 65 6f 6d 65 74 72 79 54 79 70 65 28 67 65  _GeometryType(ge
2080: 6f 6d 65 74 72 79 29 2c 20 53 54 5f 53 72 69 64  ometry), ST_Srid
2090: 28 67 65 6f 6d 65 74 72 79 29 2c 20 43 6f 6f 72  (geometry), Coor
20a0: 64 44 69 6d 65 6e 73 69 6f 6e 28 67 65 6f 6d 65  dDimension(geome
20b0: 74 72 79 29 0d 0a 46 52 4f 4d 20 66 72 6f 6d 5f  try)..FROM from_
20c0: 70 6f 73 74 67 69 73 3b 0d 0a 2d 2d 2d 2d 2d 2d  postgis;..------
20d0: 2d 2d 2d 2d 2d 2d 0d 0a 4c 49 4e 45 53 54 52 49  ------..LINESTRI
20e0: 4e 47 7c 32 35 38 33 32 7c 58 59 0d 0a 0d 0a 53  NG|25832|XY....S
20f0: 45 4c 45 43 54 20 52 65 63 6f 76 65 72 47 65 6f  ELECT RecoverGeo
2100: 6d 65 74 72 79 43 6f 6c 75 6d 6e 28 27 66 72 6f  metryColumn('fro
2110: 6d 5f 70 6f 73 74 67 69 73 27 2c 20 27 67 65 6f  m_postgis', 'geo
2120: 6d 65 74 72 79 27 2c 20 32 35 38 33 32 2c 20 27  metry', 25832, '
2130: 4c 49 4e 45 53 54 52 49 4e 47 27 2c 20 27 58 59  LINESTRING', 'XY
2140: 27 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ');..-----------
2150: 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 62 61 74 69 6d  -..1..</verbatim
2160: 3e 0d 0a 54 68 69 73 20 73 65 71 75 65 6e 63 65  >..This sequence
2170: 20 6f 66 20 53 51 4c 20 73 74 61 74 65 6d 65 6e   of SQL statemen
2180: 74 73 20 28 53 70 61 74 69 61 4c 69 74 65 20 73  ts (SpatiaLite s
2190: 75 70 70 6f 72 74 20 69 73 20 73 74 72 69 63 74  upport is strict
21a0: 6c 79 20 72 65 71 75 69 72 65 64 29 20 77 69 6c  ly required) wil
21b0: 6c 20 74 72 61 6e 73 66 65 72 20 61 20 66 75 6c  l transfer a ful
21c0: 6c 79 20 71 75 61 6c 69 66 69 65 64 20 47 65 6f  ly qualified Geo
21d0: 6d 65 74 72 79 20 74 61 62 6c 65 20 66 72 6f 6d  metry table from
21e0: 20 50 6f 73 74 47 49 53 20 74 6f 20 53 70 61 74   PostGIS to Spat
21f0: 69 61 4c 69 74 65 3a 0d 0a 3c 75 6c 3e 0d 0a 3c  iaLite:..<ul>..<
2200: 6c 69 3e 3c 62 3e 73 74 65 70 20 31 3c 2f 62 3e  li><b>step 1</b>
2210: 3a 20 66 69 72 73 74 20 77 65 27 6c 6c 20 74 72  : first we'll tr
2220: 61 6e 73 66 65 72 20 74 68 65 20 77 68 6f 6c 65  ansfer the whole
2230: 20 50 6f 73 74 47 49 53 20 74 61 62 6c 65 20 69   PostGIS table i
2240: 6e 74 6f 20 53 51 4c 69 74 65 3b 20 67 65 6f 6d  nto SQLite; geom
2250: 65 74 72 69 65 73 20 61 72 65 20 73 74 69 6c 6c  etries are still
2260: 20 72 65 70 72 65 73 65 6e 74 65 64 20 62 79 20   represented by 
2270: 74 68 65 69 72 20 3c 62 3e 45 57 4b 42 3c 2f 62  their <b>EWKB</b
2280: 3e 20 68 65 78 61 64 65 63 69 6d 61 6c 20 6e 6f  > hexadecimal no
2290: 74 61 74 69 6f 6e 73 2e 3c 2f 6c 69 3e 0d 0a 3c  tations.</li>..<
22a0: 6c 69 3e 3c 62 3e 73 74 65 70 20 32 3c 2f 62 3e  li><b>step 2</b>
22b0: 3a 20 74 68 65 6e 20 77 65 27 6c 6c 20 75 73 65  : then we'll use
22c0: 20 74 68 65 20 3c 62 3e 47 65 6f 6d 46 72 6f 6d   the <b>GeomFrom
22d0: 45 57 4b 42 28 29 3c 2f 62 3e 20 53 51 4c 20 66  EWKB()</b> SQL f
22e0: 75 6e 63 74 69 6f 6e 20 73 6f 20 74 6f 20 67 65  unction so to ge
22f0: 74 20 74 68 65 20 63 6f 72 72 65 73 70 6f 6e 64  t the correspond
2300: 69 6e 67 20 3c 62 3e 53 70 61 74 69 61 4c 69 74  ing <b>SpatiaLit
2310: 65 27 73 20 42 4c 4f 42 3c 2f 62 3e 20 66 6f 72  e's BLOB</b> for
2320: 20 65 61 63 68 20 67 65 6f 6d 65 74 72 79 2e 3c   each geometry.<
2330: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 73 74 65  /li>..<li><b>ste
2340: 70 20 33 3c 2f 62 3e 3a 20 6e 6f 77 20 77 65 20  p 3</b>: now we 
2350: 73 69 6d 70 6c 79 20 68 61 76 65 20 74 6f 20 64  simply have to d
2360: 69 73 63 6f 76 65 72 20 74 68 65 20 54 79 70 65  iscover the Type
2370: 2c 20 53 52 49 44 20 61 6e 64 20 44 69 6d 65 6e  , SRID and Dimen
2380: 73 69 6f 6e 73 20 64 65 63 6c 61 72 65 64 20 62  sions declared b
2390: 79 20 74 68 65 73 65 20 67 65 6f 6d 65 74 72 69  y these geometri
23a0: 65 73 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62  es.</li>..<li><b
23b0: 3e 73 74 65 70 20 34 3c 2f 62 3e 3a 20 61 6e 64  >step 4</b>: and
23c0: 20 66 69 6e 61 6c 6c 79 20 77 65 20 63 61 6e 20   finally we can 
23d0: 6e 6f 77 20 72 65 63 6f 76 65 72 20 61 20 66 75  now recover a fu
23e0: 6c 6c 20 71 75 61 6c 69 66 69 65 64 20 53 70 61  ll qualified Spa
23f0: 74 69 61 4c 69 74 65 27 73 20 6f 77 6e 20 28 3c  tiaLite's own (<
2400: 69 3e 6e 61 74 69 76 65 3c 2f 69 3e 29 20 47 65  i>native</i>) Ge
2410: 6f 6d 65 74 72 79 20 63 6f 6c 75 6d 6e 2e 3c 2f  ometry column.</
2420: 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 62 72 3e 0d 0a  li>..</ul><br>..
2430: 3c 68 72 3e 0d 0a 3c 68 33 3e 65 78 70 6f 72 74  <hr>..<h3>export
2440: 69 6e 67 20 64 61 74 61 20 66 72 6f 6d 20 53 51  ing data from SQ
2450: 4c 69 74 65 20 74 6f 20 50 6f 73 74 67 72 65 73  Lite to Postgres
2460: 2f 50 6f 73 74 47 49 53 3c 2f 68 33 3e 0d 0a 46  /PostGIS</h3>..F
2470: 6f 72 20 72 61 74 68 65 72 20 6f 62 76 69 6f 75  or rather obviou
2480: 73 20 73 65 63 75 72 69 74 79 20 72 65 61 73 6f  s security reaso
2490: 6e 73 2c 20 61 6c 6c 20 56 69 72 74 75 61 6c 50  ns, all VirtualP
24a0: 6f 73 74 67 72 65 73 20 74 61 62 6c 65 73 20 61  ostgres tables a
24b0: 72 65 20 64 65 63 6c 61 72 65 64 20 74 6f 20 62  re declared to b
24c0: 65 20 3c 69 3e 72 65 61 64 2d 6f 6e 6c 79 3c 2f  e <i>read-only</
24d0: 69 3e 20 62 79 20 64 65 66 61 75 6c 74 2e 3c 62  i> by default.<b
24e0: 72 3e 0d 0a 54 68 69 73 20 61 63 74 75 61 6c 6c  r>..This actuall
24f0: 79 20 6d 65 61 6e 73 20 74 68 61 74 20 79 6f 75  y means that you
2500: 20 61 72 65 20 65 6e 61 62 6c 65 64 20 74 6f 20   are enabled to 
2510: 65 78 65 63 75 74 65 20 61 6e 79 20 70 6f 73 73  execute any poss
2520: 69 62 6c 65 20 3c 62 3e 53 45 4c 45 43 54 3c 2f  ible <b>SELECT</
2530: 62 3e 20 71 75 65 72 79 2c 20 62 75 74 20 61 6e  b> query, but an
2540: 79 20 3c 62 3e 49 4e 53 45 52 54 3c 2f 62 3e 2c  y <b>INSERT</b>,
2550: 20 3c 62 3e 55 50 44 41 54 45 3c 2f 62 3e 20 6f   <b>UPDATE</b> o
2560: 72 20 3c 62 3e 44 45 4c 45 54 45 3c 2f 62 3e 20  r <b>DELETE</b> 
2570: 6f 70 65 72 61 74 69 6f 6e 20 61 66 66 65 63 74  operation affect
2580: 69 6e 67 20 74 68 65 20 50 6f 73 74 67 72 65 73  ing the Postgres
2590: 20 44 42 4d 53 20 69 73 20 73 74 72 69 63 74 6c   DBMS is strictl
25a0: 79 20 66 6f 72 62 69 64 64 65 6e 2e 0d 0a 3c 76  y forbidden...<v
25b0: 65 72 62 61 74 69 6d 3e 0d 0a 43 52 45 41 54 45  erbatim>..CREATE
25c0: 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 70   VIRTUAL TABLE p
25d0: 67 5f 6f 75 74 20 0d 0a 20 20 20 20 55 53 49 4e  g_out ..    USIN
25e0: 47 20 56 69 72 74 75 61 6c 50 6f 73 74 67 72 65  G VirtualPostgre
25f0: 73 20 28 27 68 6f 73 74 61 64 64 72 3d 31 39 32  s ('hostaddr=192
2600: 2e 31 36 38 2e 31 2e 39 31 20 70 6f 72 74 3d 35  .168.1.91 port=5
2610: 34 33 32 20 64 62 6e 61 6d 65 3d 67 69 73 20 75  432 dbname=gis u
2620: 73 65 72 3d 73 61 6e 64 72 6f 20 70 61 73 73 77  ser=sandro passw
2630: 6f 72 64 3d 73 65 63 72 65 74 27 2c 20 6d 79 5f  ord=secret', my_
2640: 73 63 68 65 6d 61 2c 20 6d 79 5f 74 61 62 6c 65  schema, my_table
2650: 2c 20 57 29 3b 0d 0a 3c 2f 76 65 72 62 61 74 69  , W);..</verbati
2660: 6d 3e 0d 0a 41 6e 79 77 61 79 20 79 6f 75 20 63  m>..Anyway you c
2670: 61 6e 20 65 78 70 6c 69 63 69 74 6c 79 20 72 65  an explicitly re
2680: 71 75 65 73 74 20 61 20 56 69 72 74 75 61 6c 50  quest a VirtualP
2690: 6f 73 74 67 72 65 73 20 74 61 62 6c 65 20 74 6f  ostgres table to
26a0: 20 73 75 70 70 6f 72 74 20 75 6e 63 6f 6e 73 74   support unconst
26b0: 72 61 69 6e 65 64 20 3c 69 3e 72 65 61 64 2d 77  rained <i>read-w
26c0: 72 69 74 65 3c 2f 69 3e 20 6f 70 65 72 61 74 69  rite</i> operati
26d0: 6f 6e 73 2c 20 74 68 69 73 20 69 6e 63 6c 75 64  ons, this includ
26e0: 69 6e 67 20 61 6e 79 20 3c 62 3e 49 4e 53 45 52  ing any <b>INSER
26f0: 54 3c 2f 62 3e 2c 20 3c 62 3e 55 50 44 41 54 45  T</b>, <b>UPDATE
2700: 3c 2f 62 3e 20 6f 72 20 3c 62 3e 44 45 4c 45 54  </b> or <b>DELET
2710: 45 3c 2f 62 3e 20 73 74 61 74 65 6d 65 6e 74 20  E</b> statement 
2720: 61 66 66 65 63 74 69 6e 67 20 74 68 65 20 50 6f  affecting the Po
2730: 73 74 67 72 65 73 20 44 42 4d 53 2e 3c 62 72 3e  stgres DBMS.<br>
2740: 0d 0a 49 6e 20 74 68 69 73 20 63 61 73 65 20 79  ..In this case y
2750: 6f 75 20 73 69 6d 70 6c 79 20 68 61 76 65 20 74  ou simply have t
2760: 6f 20 70 61 73 73 20 61 20 66 75 72 74 68 65 72  o pass a further
2770: 20 66 6f 75 72 74 68 20 61 72 67 75 6d 65 6e 74   fourth argument
2780: 20 69 6e 74 6f 20 74 68 65 20 3c 62 3e 55 53 49   into the <b>USI
2790: 4e 47 3c 2f 62 3e 20 63 6c 61 75 73 65 20 65 78  NG</b> clause ex
27a0: 61 63 74 6c 79 20 63 6f 72 72 65 73 70 6f 6e 64  actly correspond
27b0: 69 6e 67 20 74 6f 20 74 68 65 20 6c 65 74 74 65  ing to the lette
27c0: 72 20 3c 62 3e 57 3c 2f 62 3e 2e 0d 0a 3c 76 65  r <b>W</b>...<ve
27d0: 72 62 61 74 69 6d 3e 0d 0a 44 45 4c 45 54 45 20  rbatim>..DELETE 
27e0: 46 52 4f 4d 20 70 67 5f 6f 75 74 3b 0d 0a 0d 0a  FROM pg_out;....
27f0: 49 4e 53 45 52 54 20 49 4e 54 4f 20 70 67 5f 6f  INSERT INTO pg_o
2800: 75 74 20 28 66 6c 64 5f 61 2c 20 66 6c 64 5f 62  ut (fld_a, fld_b
2810: 2c 20 66 6c 64 5f 63 2c 20 67 65 6f 6d 65 74 72  , fld_c, geometr
2820: 79 29 0d 0a 53 45 4c 45 43 54 20 66 6c 64 5f 61  y)..SELECT fld_a
2830: 2c 20 66 6c 64 5f 62 2c 20 66 6c 64 5f 63 2c 20  , fld_b, fld_c, 
2840: 41 73 45 57 4b 42 28 67 65 6f 6d 65 74 72 79 29  AsEWKB(geometry)
2850: 0d 0a 66 72 6f 6d 20 73 6f 6d 65 5f 74 61 62 6c  ..from some_tabl
2860: 65 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d  e;..</verbatim>.
2870: 0a 49 6e 20 74 68 65 20 61 62 6f 76 65 20 65 78  .In the above ex
2880: 61 6d 70 6c 65 20 77 65 27 6c 6c 20 64 65 6c 65  ample we'll dele
2890: 74 65 20 66 69 72 73 74 20 61 6e 79 20 61 6c 72  te first any alr
28a0: 65 61 64 79 20 65 78 69 73 74 69 6e 67 20 72 6f  eady existing ro
28b0: 77 20 66 72 6f 6d 20 74 68 65 20 50 6f 73 74 47  w from the PostG
28c0: 49 53 20 74 61 62 6c 65 3b 20 74 68 65 6e 20 77  IS table; then w
28d0: 65 27 6c 6c 20 73 69 6d 70 6c 79 20 74 72 61 6e  e'll simply tran
28e0: 73 66 65 72 20 74 68 65 20 77 68 6f 6c 65 20 74  sfer the whole t
28f0: 61 62 6c 65 20 66 72 6f 6d 20 53 70 61 74 69 61  able from Spatia
2900: 4c 69 74 65 20 69 6e 74 6f 20 50 6f 73 74 47 49  Lite into PostGI
2910: 53 2e 3c 62 72 3e 0d 0a 50 6c 65 61 73 65 20 6e  S.<br>..Please n
2920: 6f 74 65 2c 20 77 65 27 6c 6c 20 69 6e 76 6f 6b  ote, we'll invok
2930: 65 20 74 68 65 20 3c 62 3e 41 73 45 57 4b 42 28  e the <b>AsEWKB(
2940: 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69  )</b> SQL functi
2950: 6f 6e 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 63  on in order to c
2960: 6f 6e 76 65 72 74 20 61 6e 79 20 53 70 61 74 69  onvert any Spati
2970: 61 4c 69 74 65 27 73 20 6f 77 6e 20 3c 62 3e 42  aLite's own <b>B
2980: 4c 4f 42 3c 2f 62 3e 20 67 65 6f 6d 65 74 72 79  LOB</b> geometry
2990: 20 69 6e 74 6f 20 74 68 65 20 65 71 75 69 76 61   into the equiva
29a0: 6c 65 6e 74 20 3c 62 3e 42 59 54 45 41 20 45 57  lent <b>BYTEA EW
29b0: 4b 42 3c 2f 62 3e 20 6e 6f 74 61 74 69 6f 6e 20  KB</b> notation 
29c0: 72 65 71 75 69 72 65 64 20 62 79 20 50 6f 73 74  required by Post
29d0: 47 49 53 2e 3c 62 72 3e 0d 0a 3c 74 61 62 6c 65  GIS.<br>..<table
29e0: 20 62 67 63 6f 6c 6f 72 3d 22 23 66 66 66 66 65   bgcolor="#ffffe
29f0: 38 22 20 77 69 64 74 68 3d 22 31 30 30 25 22 3e  8" width="100%">
2a00: 0d 0a 3c 74 72 3e 3c 74 64 20 61 6c 69 67 6e 3d  ..<tr><td align=
2a10: 22 63 65 6e 74 65 72 22 3e 3c 62 3e 43 61 76 65  "center"><b>Cave
2a20: 61 74 3a 20 41 73 45 57 4b 42 28 29 3c 2f 62 3e  at: AsEWKB()</b>
2a30: 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e  </td></tr>..<tr>
2a40: 3c 74 64 3e 3c 68 72 3e 3c 2f 74 64 3e 3c 2f 74  <td><hr></td></t
2a50: 72 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 0d 0a 41 6e  r>..<tr><td>..An
2a60: 79 20 70 72 65 76 69 6f 75 73 20 76 65 72 73 69  y previous versi
2a70: 6f 6e 20 6f 66 20 53 70 61 74 69 61 4c 69 74 65  on of SpatiaLite
2a80: 20 28 74 68 69 73 20 69 6e 63 6c 75 64 69 6e 67   (this including
2a90: 20 74 68 65 20 63 75 72 72 65 6e 74 20 3c 62 3e   the current <b>
2aa0: 34 2e 31 2e 31 3c 2f 62 3e 29 20 73 75 70 70 6f  4.1.1</b>) suppo
2ab0: 72 74 65 64 20 61 20 62 75 67 67 69 73 68 20 3c  rted a buggish <
2ac0: 62 3e 41 73 45 57 4b 42 28 29 3c 2f 62 3e 20 69  b>AsEWKB()</b> i
2ad0: 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 63 6f  mplementation co
2ae0: 6d 70 6c 65 74 65 6c 79 20 75 6e 61 62 6c 65 20  mpletely unable 
2af0: 74 6f 20 63 72 65 61 74 65 20 76 61 6c 69 64 20  to create valid 
2b00: 45 57 4b 42 20 47 65 6f 6d 65 74 72 69 65 73 20  EWKB Geometries 
2b10: 74 6f 20 62 65 20 70 61 73 73 65 64 20 74 6f 20  to be passed to 
2b20: 50 6f 73 74 47 49 53 2e 3c 62 72 3e 0d 0a 49 20  PostGIS.<br>..I 
2b30: 70 72 65 73 75 6d 65 20 74 68 61 74 20 6e 6f 62  presume that nob
2b40: 6f 64 79 20 72 65 61 6c 6c 79 20 61 74 74 65 6d  ody really attem
2b50: 70 74 65 64 20 74 6f 20 75 73 65 20 74 68 69 73  pted to use this
2b60: 20 66 75 6e 63 74 69 6f 6e 20 62 65 66 6f 72 65   function before
2b70: 2c 20 73 6f 20 74 68 69 73 20 62 75 67 20 70 61  , so this bug pa
2b80: 73 73 65 64 20 63 6f 6d 70 6c 65 74 65 6c 79 20  ssed completely 
2b90: 75 6e 6e 6f 74 69 63 65 64 20 73 69 6e 63 65 20  unnoticed since 
2ba0: 6e 6f 77 2e 3c 62 72 3e 0d 0a 55 73 69 6e 67 20  now.<br>..Using 
2bb0: 74 68 65 20 6c 61 74 65 73 74 20 76 65 72 73 69  the latest versi
2bc0: 6f 6e 20 6f 66 20 74 68 65 20 63 6f 64 65 20 61  on of the code a
2bd0: 76 61 69 6c 61 62 6c 65 20 66 72 6f 6d 20 74 68  vailable from th
2be0: 65 20 46 6f 73 73 69 6c 20 72 65 70 6f 73 69 74  e Fossil reposit
2bf0: 6f 72 79 20 69 73 20 73 74 72 69 63 74 6c 79 20  ory is strictly 
2c00: 72 65 71 75 69 72 65 64 20 73 6f 20 74 6f 20 72  required so to r
2c10: 65 61 6c 6c 79 20 67 65 74 20 61 20 77 6f 72 6b  eally get a work
2c20: 69 6e 67 20 41 73 45 57 4b 4b 28 29 2e 0d 0a 3c  ing AsEWKK()...<
2c30: 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 2f 74 61 62  /td></tr>..</tab
2c40: 6c 65 3e 0a 5a 20 39 35 31 33 34 63 31 39 66 61  le>.Z 95134c19fa
2c50: 61 61 31 38 35 39 35 62 66 35 39 66 37 31 66 34  aa18595bf59f71f4
2c60: 61 62 66 36 30 65 0a                             abf60e.