Artifact 701eea8e48f630d8fc398fd44d6736e83c3c7bb2:
0000: 44 20 32 30 31 38 2d 30 37 2d 31 35 54 31 37 3a D 2018-07-15T17: 0010: 34 34 3a 30 38 2e 38 32 36 0a 4c 20 74 75 74 6f 44:08.826.L tuto 0020: 72 69 61 6c 0a 50 20 62 63 34 38 35 64 39 64 38 rial.P bc485d9d8 0030: 35 39 63 32 36 39 61 32 32 63 33 34 64 66 63 65 59c269a22c34dfce 0040: 33 38 61 61 34 38 33 65 33 62 33 39 62 65 62 0a 38aa483e3b39beb. 0050: 55 20 73 61 6e 64 72 6f 0a 57 20 31 34 38 36 33 U sandro.W 14863 0060: 0a 42 61 63 6b 20 74 6f 20 3c 62 3e 56 69 72 74 .Back to <b>Virt 0070: 75 61 6c 50 47 3c 2f 62 3e 20 3c 61 20 68 72 65 ualPG</b> <a hre 0080: 66 3d 22 68 74 74 70 73 3a 2f 2f 77 77 77 2e 67 f="https://www.g 0090: 61 69 61 2d 67 69 73 2e 69 74 2f 66 6f 73 73 69 aia-gis.it/fossi 00a0: 6c 2f 76 69 72 74 75 61 6c 70 67 2f 69 6e 64 65 l/virtualpg/inde 00b0: 78 22 3e 68 6f 6d 65 20 70 61 67 65 3c 2f 61 3e x">home page</a> 00c0: 0d 0a 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 68 32 3e ..<br><br>..<h2> 00d0: 55 70 64 61 74 65 64 20 64 6f 63 75 6d 65 6e 74 Updated document 00e0: 61 74 69 6f 6e 20 73 75 70 70 6f 72 74 69 6e 67 ation supporting 00f0: 20 56 69 72 74 75 61 6c 50 47 20 76 32 3c 2f 68 VirtualPG v2</h 0100: 32 3e 0d 0a 3c 74 61 62 6c 65 20 63 65 6c 6c 73 2>..<table cells 0110: 70 61 63 69 6e 67 3d 22 36 22 20 63 65 6c 6c 70 pacing="6" cellp 0120: 61 64 64 69 6e 67 3d 22 36 22 20 62 67 63 6f 6c adding="6" bgcol 0130: 6f 72 3d 22 23 66 66 64 30 38 30 22 3e 3c 74 72 or="#ffd080"><tr 0140: 3e 3c 74 64 3e 0d 0a 3c 68 33 3e 57 61 72 6e 69 ><td>..<h3>Warni 0150: 6e 67 3c 2f 68 33 3e 0d 0a 54 68 65 20 66 6f 6c ng</h3>..The fol 0160: 6c 6f 77 69 6e 67 20 69 6e 66 6f 72 6d 61 74 69 lowing informati 0170: 6f 6e 73 20 63 6f 72 72 65 73 70 6f 6e 64 20 74 ons correspond t 0180: 6f 20 74 68 65 20 6d 6f 73 74 20 72 65 63 65 6e o the most recen 0190: 74 20 3c 62 3e 56 65 72 73 69 6f 6e 20 32 3c 2f t <b>Version 2</ 01a0: 62 3e 20 6f 66 20 56 69 72 74 75 61 6c 50 47 2c b> of VirtualPG, 01b0: 20 61 6e 64 20 63 6f 75 6c 64 20 6e 6f 74 20 61 and could not a 01c0: 6c 77 61 79 73 20 61 64 65 71 75 61 74 65 6c 79 lways adequately 01d0: 20 63 6f 76 65 72 20 74 68 65 20 70 72 65 76 69 cover the previ 01e0: 6f 75 73 20 76 65 72 73 69 6f 6e 73 2c 20 74 68 ous versions, th 01f0: 61 74 20 61 72 65 20 6e 6f 77 20 64 65 63 6c 61 at are now decla 0200: 72 65 64 20 6f 62 73 6f 6c 65 74 65 2e 3c 62 72 red obsolete.<br 0210: 3e 0d 0a 49 66 20 79 6f 75 20 61 72 65 20 73 74 >..If you are st 0220: 69 6c 6c 20 75 73 69 6e 67 20 61 6e 79 20 70 72 ill using any pr 0230: 65 76 69 6f 75 73 20 76 65 72 73 69 6f 6e 20 79 evious version y 0240: 6f 75 20 61 72 65 20 77 61 72 6d 6c 79 20 72 65 ou are warmly re 0250: 63 63 6f 6d 6d 65 6e 64 65 64 20 74 6f 20 71 75 ccommended to qu 0260: 69 63 6b 6c 79 20 75 70 64 61 74 65 20 79 6f 75 ickly update you 0270: 72 20 73 6f 66 74 77 61 72 65 2e 0d 0a 3c 2f 74 r software...</t 0280: 64 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 0d d></tr></table>. 0290: 0a 3c 68 32 3e 61 62 6f 75 74 20 56 69 72 74 75 .<h2>about Virtu 02a0: 61 6c 50 47 3c 2f 68 32 3e 0d 0a 3c 62 3e 56 69 alPG</h2>..<b>Vi 02b0: 72 74 75 61 6c 50 47 20 32 3c 2f 62 3e 20 69 73 rtualPG 2</b> is 02c0: 20 61 76 61 69 6c 61 62 6c 65 20 62 6f 74 68 20 available both 02d0: 61 73 20 61 20 3c 69 3e 63 6c 61 73 73 69 63 20 as a <i>classic 02e0: 3c 62 3e 43 2f 43 2b 2b 3c 2f 62 3e 20 6c 69 62 <b>C/C++</b> lib 02f0: 72 61 72 79 3c 2f 69 3e 20 61 6e 64 20 61 73 20 rary</i> and as 0300: 61 20 3c 69 3e 6c 6f 61 64 61 62 6c 65 20 64 79 a <i>loadable dy 0310: 6e 61 6d 69 63 20 65 78 74 65 6e 73 69 6f 6e 20 namic extension 0320: 6d 6f 64 75 6c 65 3c 2f 69 3e 20 66 6f 72 20 62 module</i> for b 0330: 6f 74 68 20 3c 62 3e 53 51 4c 69 74 65 3c 2f 62 oth <b>SQLite</b 0340: 3e 20 61 6e 64 20 3c 62 3e 53 70 61 74 69 61 4c > and <b>SpatiaL 0350: 69 74 65 3c 2f 62 3e 2e 3c 62 72 3e 0d 0a 54 68 ite</b>.<br>..Th 0360: 65 20 69 6e 74 65 6e 64 65 64 20 73 63 6f 70 65 e intended scope 0370: 20 6f 66 20 56 69 72 74 75 61 6c 50 47 20 69 73 of VirtualPG is 0380: 20 73 75 70 70 6f 72 74 69 6e 67 20 64 69 72 65 supporting dire 0390: 63 74 20 64 61 74 61 20 65 78 63 68 61 6e 67 65 ct data exchange 03a0: 20 66 6f 72 6d 2f 74 6f 20 3c 62 3e 50 6f 73 74 form/to <b>Post 03b0: 67 72 65 53 51 4c 3c 2f 62 3e 20 2f 20 3c 62 3e greSQL</b> / <b> 03c0: 50 6f 73 74 47 49 53 3c 2f 62 3e 20 74 61 72 67 PostGIS</b> targ 03d0: 65 74 73 20 61 6e 64 20 3c 62 3e 53 51 4c 69 74 ets and <b>SQLit 03e0: 65 3c 2f 62 3e 20 73 69 6d 70 6c 79 20 75 73 69 e</b> simply usi 03f0: 6e 67 20 62 61 73 69 63 2c 20 70 6c 61 69 6e 20 ng basic, plain 0400: 3c 69 3e 53 51 4c 20 73 74 61 74 65 6d 65 6e 74 <i>SQL statement 0410: 73 3c 2f 69 3e 2e 3c 62 72 3e 3c 62 72 3e 0d 0a s</i>.<br><br>.. 0420: 3c 68 72 3e 0d 0a 3c 68 33 3e 56 69 72 74 75 61 <hr>..<h3>Virtua 0430: 6c 50 47 20 61 73 20 61 20 73 74 61 6e 64 61 72 lPG as a standar 0440: 64 20 43 2f 43 2b 2b 20 6c 69 62 72 61 72 79 3c d C/C++ library< 0450: 2f 68 33 3e 0d 0a 54 68 65 72 65 20 69 73 20 76 /h3>..There is v 0460: 65 72 79 20 6c 69 74 74 6c 65 20 74 6f 20 73 61 ery little to sa 0470: 79 20 61 62 6f 75 74 20 56 69 72 74 75 61 6c 50 y about VirtualP 0480: 47 20 61 73 20 61 20 6c 69 62 72 61 72 79 2c 20 G as a library, 0490: 62 65 63 61 75 73 65 20 69 74 20 69 6d 70 6c 65 because it imple 04a0: 6d 65 6e 74 73 20 6a 75 73 74 20 74 77 6f 20 43 ments just two C 04b0: 20 66 75 6e 63 74 69 6f 6e 73 3a 0d 0a 3c 6f 6c functions:..<ol 04c0: 3e 0d 0a 3c 6c 69 3e 3c 62 3e 56 49 52 54 55 41 >..<li><b>VIRTUA 04d0: 4c 50 47 5f 44 45 43 4c 41 52 45 20 63 6f 6e 73 LPG_DECLARE cons 04e0: 74 20 63 68 61 72 20 2a 76 69 72 74 75 61 6c 70 t char *virtualp 04f0: 67 5f 76 65 72 73 69 6f 6e 20 28 76 6f 69 64 29 g_version (void) 0500: 3b 3c 2f 62 3e 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 ;</b>..<ul>..<li 0510: 3e 74 68 69 73 20 66 69 72 73 74 20 41 50 49 20 >this first API 0520: 77 69 6c 6c 20 72 65 74 75 72 6e 20 74 68 65 20 will return the 0530: 63 75 72 72 65 6e 74 20 76 65 72 73 69 6f 6e 20 current version 0540: 6f 66 20 74 68 65 20 6c 69 62 72 61 72 79 2e 3c of the library.< 0550: 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 2f 6c 69 3e /li>..</ul></li> 0560: 0d 0a 3c 6c 69 3e 3c 62 3e 56 49 52 54 55 41 4c ..<li><b>VIRTUAL 0570: 50 47 5f 44 45 43 4c 41 52 45 20 69 6e 74 20 76 PG_DECLARE int v 0580: 69 72 74 75 61 6c 70 67 5f 65 78 74 65 6e 73 69 irtualpg_extensi 0590: 6f 6e 5f 69 6e 69 74 20 28 73 71 6c 69 74 65 33 on_init (sqlite3 05a0: 20 2a 64 62 5f 68 61 6e 64 6c 65 29 3b 3c 2f 62 *db_handle);</b 05b0: 3e 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 74 68 69 >..<ul>..<li>thi 05c0: 73 20 73 65 63 6f 6e 64 20 41 50 49 20 69 73 20 s second API is 05d0: 69 6e 74 65 6e 65 64 20 74 6f 20 69 6e 69 74 69 intened to initi 05e0: 61 6c 69 7a 65 20 74 68 65 20 56 69 72 74 75 61 alize the Virtua 05f0: 6c 50 47 20 65 78 74 65 6e 73 69 6f 6e 20 6d 6f lPG extension mo 0600: 64 75 6c 65 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 dule:..<ul>..<li 0610: 3e 3c 62 3e 64 62 5f 68 61 6e 64 6c 65 3c 2f 62 ><b>db_handle</b 0620: 3e 20 6d 75 73 74 20 62 65 20 61 20 76 61 6c 69 > must be a vali 0630: 64 20 68 61 6e 64 6c 65 20 74 6f 20 73 6f 6d 65 d handle to some 0640: 20 61 6c 72 65 61 64 79 20 65 73 74 61 62 6c 69 already establi 0650: 73 68 65 64 20 53 51 4c 69 74 65 20 63 6f 6e 6e shed SQLite conn 0660: 65 63 74 69 6f 6e 2e 3c 2f 6c 69 3e 0d 0a 3c 6c ection.</li>..<l 0670: 69 3e 74 68 65 20 72 65 74 75 72 6e 20 76 61 6c i>the return val 0680: 75 65 20 77 69 6c 6c 20 62 65 20 3c 62 3e 53 51 ue will be <b>SQ 0690: 4c 49 54 45 5f 4f 4b 3c 2f 62 3e 20 69 66 20 74 LITE_OK</b> if t 06a0: 68 65 20 65 78 74 65 6e 73 69 6f 6e 20 6d 6f 64 he extension mod 06b0: 75 6c 65 20 68 61 73 20 62 65 65 6e 20 73 75 63 ule has been suc 06c0: 63 65 73 66 75 6c 6c 79 20 20 69 6e 69 74 69 61 cesfully initia 06d0: 6c 69 7a 65 64 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 lized.</li>..</u 06e0: 6c 3e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 2f l></li>..</ul></ 06f0: 6c 69 3e 0d 0a 3c 2f 6f 6c 3e 0d 0a 3c 62 3e 4e li>..</ol>..<b>N 0700: 6f 74 65 73 3c 2f 62 3e 3a 3c 62 72 3e 0d 0a 3c otes</b>:<br>..< 0710: 75 6c 3e 0d 0a 3c 6c 69 3e 74 68 65 20 3c 62 3e ul>..<li>the <b> 0720: 56 69 72 74 75 61 6c 50 47 3c 2f 62 3e 20 65 78 VirtualPG</b> ex 0730: 74 65 6e 73 69 6f 6e 20 64 6f 65 73 20 6e 6f 74 tension does not 0740: 20 6e 65 63 65 73 73 61 72 69 6c 79 20 72 65 71 necessarily req 0750: 75 69 72 65 20 74 6f 20 62 65 20 73 75 70 70 6f uire to be suppo 0760: 72 74 65 64 20 62 79 20 74 68 65 20 3c 62 3e 53 rted by the <b>S 0770: 70 61 74 69 61 4c 69 74 65 3c 2f 62 3e 20 65 78 patiaLite</b> ex 0780: 74 65 6e 73 69 6f 6e 3b 20 74 68 65 79 20 61 72 tension; they ar 0790: 65 20 69 6e 64 65 70 65 6e 64 65 6e 74 20 74 68 e independent th 07a0: 65 20 6f 6e 65 20 66 72 6f 6d 20 74 68 65 20 6f e one from the o 07b0: 74 68 65 72 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e ther.</li>..<li> 07c0: 74 68 65 20 72 65 6c 61 74 69 76 65 20 6f 72 64 the relative ord 07d0: 65 72 20 69 6e 20 77 68 69 63 68 20 74 68 65 20 er in which the 07e0: 74 77 6f 20 65 78 74 65 6e 73 69 6f 6e 73 20 61 two extensions a 07f0: 72 65 20 65 76 65 6e 74 75 61 6c 6c 79 20 69 6e re eventually in 0800: 69 74 69 61 6c 69 7a 65 64 20 69 73 20 61 62 73 itialized is abs 0810: 6f 6c 75 74 65 6c 79 20 6e 6f 74 20 72 65 6c 65 olutely not rele 0820: 76 61 6e 74 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e vant.</li>..<li> 0830: 68 6f 77 65 76 65 72 2c 20 77 68 65 6e 20 56 69 however, when Vi 0840: 72 74 75 61 6c 50 47 20 69 73 20 62 61 63 6b 65 rtualPG is backe 0850: 64 20 75 70 20 62 79 20 53 70 61 74 69 61 4c 69 d up by SpatiaLi 0860: 74 65 2c 20 79 6f 75 27 6c 6c 20 61 6c 77 61 79 te, you'll alway 0870: 73 20 62 65 20 61 62 6c 65 20 74 6f 20 65 6e 71 s be able to enq 0880: 75 69 72 79 20 69 6e 20 66 75 6c 6c 20 64 65 74 uiry in full det 0890: 61 69 6c 20 61 6e 79 20 65 72 72 6f 72 20 6d 65 ail any error me 08a0: 73 73 61 67 65 20 72 61 69 73 65 64 20 62 79 20 ssage raised by 08b0: 50 6f 73 74 67 72 65 53 51 4c 20 62 79 20 63 61 PostgreSQL by ca 08c0: 6c 6c 69 6e 67 20 74 68 65 20 53 51 4c 20 66 75 lling the SQL fu 08d0: 6e 63 74 69 6f 6e 20 3c 62 3e 50 6f 73 74 67 72 nction <b>Postgr 08e0: 65 53 71 6c 5f 47 65 74 4c 61 73 74 4d 65 73 73 eSql_GetLastMess 08f0: 61 67 65 28 29 3c 2f 62 3e 2e 3c 62 72 3e 0d 0a age()</b>.<br>.. 0900: 74 68 69 73 20 69 73 20 61 20 72 65 61 6c 6c 79 this is a really 0910: 20 75 73 65 66 75 6c 20 64 69 61 67 6e 6f 73 74 useful diagnost 0920: 69 63 20 66 75 6e 63 74 69 6f 6e 2c 20 61 6e 64 ic function, and 0930: 20 77 69 6c 6c 20 67 72 65 61 74 6c 79 20 69 6d will greatly im 0940: 70 72 6f 76 65 20 74 68 65 20 75 73 61 62 69 6c prove the usabil 0950: 69 74 79 20 6f 66 20 56 69 72 74 75 61 6c 50 47 ity of VirtualPG 0960: 2c 20 61 6c 6c 6f 77 69 6e 67 20 66 6f 72 20 61 , allowing for a 0970: 20 73 69 6d 70 6c 69 66 69 65 64 20 61 6e 64 20 simplified and 0980: 65 61 73 69 65 72 20 64 65 62 75 67 67 69 6e 67 easier debugging 0990: 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 77 68 65 6e .</li>..<li>when 09a0: 20 53 70 61 74 69 61 4c 69 74 65 27 73 20 73 75 SpatiaLite's su 09b0: 70 70 6f 72 74 20 69 73 20 75 6e 61 76 61 69 6c pport is unavail 09c0: 61 62 6c 65 2c 20 56 69 72 74 75 61 6c 50 47 20 able, VirtualPG 09d0: 77 69 6c 6c 20 73 69 6d 70 6c 79 20 61 74 74 65 will simply atte 09e0: 6d 70 74 20 74 6f 20 6f 75 74 70 75 74 20 74 68 mpt to output th 09f0: 65 20 65 72 72 6f 72 20 6d 65 73 73 61 67 65 20 e error message 0a00: 63 6f 6d 69 6e 67 20 66 72 6f 6d 20 50 6f 73 74 coming from Post 0a10: 67 72 65 53 51 4c 20 6f 6e 20 74 68 65 20 73 74 greSQL on the st 0a20: 61 6e 64 61 72 64 20 65 72 72 6f 72 20 28 69 66 andard error (if 0a30: 20 61 76 61 69 6c 61 62 6c 65 29 2e 3c 2f 6c 69 available).</li 0a40: 3e 0d 0a 3c 6c 69 3e 3c 62 3e 4e 6f 74 65 3c 2f >..<li><b>Note</ 0a50: 62 3e 3a 20 74 68 65 20 64 69 61 67 6e 6f 73 74 b>: the diagnost 0a60: 69 63 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 ic SQL function 0a70: 3c 62 3e 50 6f 73 74 67 72 65 53 51 4c 5f 47 65 <b>PostgreSQL_Ge 0a80: 74 4c 61 73 74 45 72 72 6f 72 28 29 20 3c 2f 62 tLastError() </b 0a90: 3e 72 65 71 75 69 72 65 73 20 75 73 69 6e 67 20 >requires using 0aa0: 53 70 61 74 69 61 4c 69 74 65 20 76 65 72 73 69 SpatiaLite versi 0ab0: 6f 6e 20 35 2e 30 2e 30 20 6f 72 20 6c 61 74 65 on 5.0.0 or late 0ac0: 72 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 62 r.</li>..</ul><b 0ad0: 72 3e 0d 0a 3c 62 3e 61 20 76 65 72 79 20 73 6b r>..<b>a very sk 0ae0: 65 6c 65 74 61 6c 20 43 20 73 6f 75 72 63 65 20 eletal C source 0af0: 73 61 6d 70 6c 65 3c 2f 62 3e 3c 62 72 3e 0d 0a sample</b><br>.. 0b00: 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 23 69 6e 63 <verbatim>..#inc 0b10: 6c 75 64 65 20 3c 73 74 64 6c 69 62 2e 68 3e 0d lude <stdlib.h>. 0b20: 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f .#include <stdio 0b30: 2e 68 3e 0d 0a 23 69 6e 63 6c 75 64 65 20 3c 73 .h>..#include <s 0b40: 71 6c 69 74 65 33 2e 68 3e 0d 0a 23 69 6e 63 6c qlite3.h>..#incl 0b50: 75 64 65 20 3c 76 69 72 74 75 61 6c 70 67 2e 68 ude <virtualpg.h 0b60: 3e 0d 0a 0d 0a 69 6e 74 0d 0a 6d 61 69 6e 20 28 >....int..main ( 0b70: 69 6e 74 20 61 72 67 63 2c 20 63 68 61 72 20 2a int argc, char * 0b80: 61 72 67 76 5b 5d 29 0d 0a 7b 0d 0a 20 20 20 20 argv[])..{.. 0b90: 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 61 74 68 const char *path 0ba0: 20 3d 20 2e 2e 2e 20 73 6f 6d 65 20 76 61 6c 75 = ... some valu 0bb0: 65 20 2e 2e 2e 2e 0d 0a 20 20 20 20 73 71 6c 69 e ...... sqli 0bc0: 74 65 33 20 2a 68 61 6e 64 6c 65 3b 0d 0a 20 20 te3 *handle;.. 0bd0: 20 20 69 6e 74 20 72 65 74 3b 0d 0a 0d 0a 2f 2a int ret;..../* 0be0: 20 6f 70 65 6e 69 6e 67 20 74 68 65 20 53 51 4c opening the SQL 0bf0: 69 74 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 2a ite connection * 0c00: 2f 0d 0a 20 20 20 20 72 65 74 20 3d 20 73 71 6c /.. ret = sql 0c10: 69 74 65 33 5f 6f 70 65 6e 5f 76 32 20 28 70 61 ite3_open_v2 (pa 0c20: 74 68 2c 20 26 68 61 6e 64 6c 65 2c 20 53 51 4c th, &handle, SQL 0c30: 49 54 45 5f 4f 50 45 4e 5f 52 45 41 44 57 52 49 ITE_OPEN_READWRI 0c40: 54 45 2c 20 4e 55 4c 4c 29 3b 0d 0a 20 20 20 20 TE, NULL);.. 0c50: 69 66 20 28 72 65 74 20 21 3d 20 53 51 4c 49 54 if (ret != SQLIT 0c60: 45 5f 4f 4b 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 E_OK).. {.. 0c70: 20 20 20 20 20 20 2e 2e 2e 20 65 72 72 6f 72 20 ... error 0c80: 68 61 6e 64 6c 69 6e 67 20 2e 2e 2e 0d 0a 20 20 handling ..... 0c90: 20 20 7d 0d 0a 0d 0a 2f 2a 20 69 6e 69 74 69 61 }..../* initia 0ca0: 6c 69 7a 69 6e 67 20 56 69 72 74 75 61 6c 50 47 lizing VirtualPG 0cb0: 20 2a 2f 0d 0a 20 20 20 20 72 65 74 20 3d 20 76 */.. ret = v 0cc0: 69 72 74 75 61 6c 70 67 5f 65 78 74 65 6e 73 69 irtualpg_extensi 0cd0: 6f 6e 5f 69 6e 69 74 20 28 68 61 6e 64 6c 65 29 on_init (handle) 0ce0: 3b 0d 0a 20 20 20 20 69 66 20 28 72 65 74 20 21 ;.. if (ret ! 0cf0: 3d 20 53 51 4c 49 54 45 5f 4f 4b 29 0d 0a 20 20 = SQLITE_OK).. 0d00: 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 2e 2e 2e {.. ... 0d10: 20 65 72 72 6f 72 20 68 61 6e 64 6c 69 6e 67 20 error handling 0d20: 2e 2e 2e 0d 0a 20 20 20 20 7d 0d 0a 20 20 20 20 ..... }.. 0d30: 65 6c 73 65 0d 0a 20 20 20 20 20 20 20 20 66 70 else.. fp 0d40: 72 69 6e 74 66 20 28 73 74 64 65 72 72 2c 20 22 rintf (stderr, " 0d50: 6f 6b 2c 20 56 69 72 74 75 61 6c 50 47 20 73 75 ok, VirtualPG su 0d60: 63 63 65 73 66 75 6c 6c 79 20 69 6e 69 74 69 61 ccesfully initia 0d70: 6c 69 7a 65 64 5c 6e 22 29 3b 0d 0a 0d 0a 2f 2a lized\n");..../* 0d80: 20 64 69 73 63 6f 6e 6e 65 63 74 69 6e 67 20 66 disconnecting f 0d90: 72 6f 6d 20 53 51 4c 69 74 65 20 61 6e 64 20 65 rom SQLite and e 0da0: 78 69 74 69 6e 67 20 2a 2f 0d 0a 20 20 20 20 73 xiting */.. s 0db0: 71 6c 69 74 65 33 5f 63 6c 6f 73 65 20 28 68 61 qlite3_close (ha 0dc0: 6e 64 6c 65 29 3b 0d 0a 20 20 20 20 72 65 74 75 ndle);.. retu 0dd0: 72 6e 20 30 3b 0d 0a 7d 0d 0a 3c 2f 76 65 72 62 rn 0;..}..</verb 0de0: 61 74 69 6d 3e 3c 62 72 3e 0d 0a 3c 62 3e 4c 69 atim><br>..<b>Li 0df0: 6e 6b 20 64 69 72 65 63 74 69 76 65 73 3c 2f 62 nk directives</b 0e00: 3e 3c 62 72 3e 0d 0a 74 68 65 20 61 62 6f 76 65 ><br>..the above 0e10: 20 43 20 73 61 6d 70 6c 65 20 6f 62 76 69 6f 75 C sample obviou 0e20: 73 6c 79 20 72 65 71 75 69 72 65 73 20 74 6f 20 sly requires to 0e30: 6c 69 6e 6b 20 62 6f 74 68 20 3c 62 3e 6c 69 62 link both <b>lib 0e40: 73 71 6c 69 74 65 33 3c 2f 62 3e 20 61 6e 64 20 sqlite3</b> and 0e50: 3c 62 3e 6c 69 62 76 69 72 74 75 61 6c 70 67 3c <b>libvirtualpg< 0e60: 2f 62 3e 20 62 75 74 20 74 68 69 73 20 6c 61 74 /b> but this lat 0e70: 65 72 20 64 65 70 65 6e 64 73 20 6f 6e 20 3c 62 er depends on <b 0e80: 3e 6c 69 62 70 71 3c 2f 62 3e 2c 20 74 68 65 20 >libpq</b>, the 0e90: 50 6f 73 74 67 72 65 53 51 4c 20 63 6c 69 65 6e PostgreSQL clien 0ea0: 74 20 6c 69 62 72 61 72 79 2e 3c 62 72 3e 0d 0a t library.<br>.. 0eb0: 73 6f 20 74 68 65 73 65 20 61 72 65 20 74 68 65 so these are the 0ec0: 20 72 65 71 75 69 72 65 64 20 64 69 72 65 63 74 required direct 0ed0: 69 76 65 73 20 66 6f 72 20 61 20 73 75 63 63 65 ives for a succe 0ee0: 73 66 75 6c 20 6c 69 6e 6b 69 6e 67 3a 20 3c 62 sful linking: <b 0ef0: 3e 2d 6c 76 69 72 74 75 61 6c 70 67 20 2d 6c 73 >-lvirtualpg -ls 0f00: 71 6c 69 74 65 33 20 2d 6c 70 71 3c 2f 62 3e 0d qlite3 -lpq</b>. 0f10: 0a 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d .<br><br>..<hr>. 0f20: 0a 3c 68 33 3e 56 69 72 74 75 61 6c 50 47 20 61 .<h3>VirtualPG a 0f30: 73 20 61 20 64 79 6e 61 6d 69 63 20 65 78 74 65 s a dynamic exte 0f40: 6e 73 69 6f 6e 20 6d 6f 64 75 6c 65 3c 2f 68 33 nsion module</h3 0f50: 3e 0d 0a 54 68 65 20 65 78 74 65 6e 73 69 6f 6e >..The extension 0f60: 20 6d 6f 64 75 6c 65 20 73 69 6d 70 6c 79 20 69 module simply i 0f70: 73 20 61 6e 20 6f 72 64 69 6e 61 72 79 20 3c 69 s an ordinary <i 0f80: 3e 64 79 6e 61 6d 69 63 20 6c 69 62 72 61 72 79 >dynamic library 0f90: 3c 2f 69 3e 20 28 3c 62 3e 2e 64 6c 6c 3c 2f 62 </i> (<b>.dll</b 0fa0: 3e 20 6f 6e 20 57 69 6e 64 6f 77 73 2c 20 3c 62 > on Windows, <b 0fb0: 3e 2e 73 6f 3c 2f 62 3e 20 6f 6e 20 55 6e 69 78 >.so</b> on Unix 0fc0: 20 61 6e 64 20 4c 69 6e 75 78 2c 20 3c 62 3e 2e and Linux, <b>. 0fd0: 64 79 6c 69 62 3c 2f 62 3e 20 6f 6e 20 4d 61 63 dylib</b> on Mac 0fe0: 20 4f 73 20 58 29 3b 20 73 6f 20 74 68 65 20 66 Os X); so the f 0ff0: 69 72 73 74 20 74 68 69 6e 67 20 74 6f 20 62 65 irst thing to be 1000: 20 64 6f 6e 65 20 69 6e 20 6f 72 64 65 72 20 74 done in order t 1010: 6f 20 61 63 74 69 76 61 74 65 20 74 68 69 73 20 o activate this 1020: 65 78 74 65 6e 73 69 6f 6e 20 69 73 20 6c 6f 61 extension is loa 1030: 64 69 6e 67 20 74 68 65 20 63 6f 72 72 65 73 70 ding the corresp 1040: 6f 6e 64 69 6e 67 20 6c 69 62 72 61 72 79 20 66 onding library f 1050: 72 6f 6d 20 61 20 76 61 6c 69 64 20 53 51 4c 69 rom a valid SQLi 1060: 74 65 2f 53 70 61 74 69 61 4c 69 74 65 20 63 6f te/SpatiaLite co 1070: 6e 6e 65 63 74 69 6f 6e 2e 0d 0a 3c 76 65 72 62 nnection...<verb 1080: 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 6c 6f atim>..SELECT lo 1090: 61 64 5f 65 78 74 65 6e 73 69 6f 6e 28 27 6d 6f ad_extension('mo 10a0: 64 5f 76 69 72 74 75 61 6c 70 67 27 29 3b 0d 0a d_virtualpg');.. 10b0: 2d 2d 2d 2d 2d 2d 0d 0a 4e 55 4c 4c 0d 0a 3c 2f ------..NULL..</ 10c0: 76 65 72 62 61 74 69 6d 3e 0d 0a 3c 74 61 62 6c verbatim>..<tabl 10d0: 65 20 62 67 63 6f 6c 6f 72 3d 22 23 66 66 66 66 e bgcolor="#ffff 10e0: 65 38 22 20 77 69 64 74 68 3d 22 31 30 30 25 22 e8" width="100%" 10f0: 3e 0d 0a 3c 74 72 3e 3c 74 64 20 61 6c 69 67 6e >..<tr><td align 1100: 3d 22 63 65 6e 74 65 72 22 3e 3c 62 3e 55 73 65 ="center"><b>Use 1110: 66 75 6c 20 68 69 6e 74 73 20 61 6e 64 20 73 75 ful hints and su 1120: 67 67 65 73 74 69 6f 6e 73 3a 20 74 72 6f 75 62 ggestions: troub 1130: 6c 65 73 68 6f 6f 74 69 6e 67 3c 2f 62 3e 3c 2f leshooting</b></ 1140: 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 td></tr>..<tr><t 1150: 64 3e 3c 68 72 3e 3c 2f 74 64 3e 3c 2f 74 72 3e d><hr></td></tr> 1160: 0d 0a 3c 74 72 3e 3c 74 64 3e 0d 0a 54 68 69 73 ..<tr><td>..This 1170: 20 6f 70 65 72 61 74 69 6f 6e 20 63 6f 75 6c 64 operation could 1180: 20 65 76 65 6e 74 75 61 6c 6c 79 20 66 61 69 6c eventually fail 1190: 20 66 6f 72 20 73 65 76 65 72 61 6c 20 64 69 66 for several dif 11a0: 66 65 72 65 6e 74 20 72 65 61 73 6f 6e 73 3a 20 ferent reasons: 11b0: 68 65 72 65 20 61 72 65 20 74 68 65 20 6d 6f 73 here are the mos 11c0: 74 20 66 72 65 71 75 65 6e 74 73 3a 0d 0a 3c 75 t frequents:..<u 11d0: 6c 3e 0d 0a 3c 6c 69 3e 59 6f 75 20 61 72 65 20 l>..<li>You are 11e0: 75 73 69 6e 67 20 73 6f 6d 65 20 6f 64 64 20 76 using some odd v 11f0: 65 72 73 69 6f 6e 20 6f 66 20 53 51 4c 69 74 65 ersion of SQLite 1200: 33 2f 6c 69 62 73 71 6c 69 74 65 33 20 66 6f 72 3/libsqlite3 for 1210: 62 69 64 64 69 6e 67 20 74 6f 20 6c 6f 61 64 20 bidding to load 1220: 61 6e 79 20 64 79 6e 61 6d 69 63 20 65 78 74 65 any dynamic exte 1230: 6e 73 69 6f 6e 73 2e 3c 62 72 3e 0d 0a 54 68 69 nsions.<br>..Thi 1240: 73 20 66 65 61 74 75 72 65 20 63 6f 75 6c 64 20 s feature could 1250: 65 76 65 6e 74 75 61 6c 6c 79 20 62 65 20 64 69 eventually be di 1260: 73 61 62 6c 65 64 20 61 74 20 62 75 69 6c 64 20 sabled at build 1270: 74 69 6d 65 3b 20 69 66 20 74 68 69 73 20 69 73 time; if this is 1280: 20 79 6f 75 72 20 63 61 73 65 20 79 6f 75 20 73 your case you s 1290: 69 6d 70 6c 65 20 68 61 76 65 20 74 6f 20 73 77 imple have to sw 12a0: 69 74 63 68 20 74 6f 20 73 6f 6d 65 20 64 69 66 itch to some dif 12b0: 66 65 72 65 6e 74 20 53 51 4c 69 74 65 20 74 6f ferent SQLite to 12c0: 6f 6c 6b 69 74 20 73 75 70 70 6f 72 74 69 6e 67 olkit supporting 12d0: 20 64 79 6e 61 6d 69 63 20 65 78 74 65 6e 73 69 dynamic extensi 12e0: 6f 6e 20 6f 72 20 62 75 69 6c 64 20 6f 6e 65 20 on or build one 12f0: 62 79 20 79 6f 75 72 73 65 6c 66 2e 3c 2f 6c 69 by yourself.</li 1300: 3e 0d 0a 3c 6c 69 3e 54 68 65 20 6f 70 65 72 61 >..<li>The opera 1310: 74 69 6e 67 20 73 79 73 74 65 6d 20 63 6f 75 6c ting system coul 1320: 64 20 62 65 20 75 6e 61 62 6c 65 20 74 6f 20 63 d be unable to c 1330: 6f 72 72 65 63 74 6c 79 20 6c 6f 63 61 74 65 20 orrectly locate 1340: 74 68 65 20 64 79 6e 61 6d 69 63 20 6c 69 62 72 the dynamic libr 1350: 61 72 79 20 74 6f 20 62 65 20 6c 6f 61 64 65 64 ary to be loaded 1360: 2e 3c 62 72 3e 0d 0a 54 68 65 20 6d 6f 73 74 20 .<br>..The most 1370: 72 65 63 65 6e 74 20 76 65 72 73 69 6f 6e 73 20 recent versions 1380: 6f 66 20 53 51 4c 69 74 65 20 61 72 65 20 73 6d of SQLite are sm 1390: 61 72 74 20 65 6e 6f 75 67 68 20 74 6f 20 61 75 art enough to au 13a0: 74 6f 6d 61 74 69 63 61 6c 6c 79 20 68 61 6e 64 tomatically hand 13b0: 6c 65 20 61 6e 79 20 70 6c 61 74 66 6f 72 6d 20 le any platform 13c0: 73 70 65 63 69 66 69 63 20 73 75 66 66 69 78 3a specific suffix: 13d0: 20 73 6f 20 79 6f 75 20 61 72 65 20 6e 6f 20 6c so you are no l 13e0: 6f 6e 67 65 72 20 72 65 71 75 69 72 65 64 20 74 onger required t 13f0: 6f 20 73 70 65 63 69 66 79 20 61 6e 79 20 3c 62 o specify any <b 1400: 3e 2e 64 6c 6c 3c 2f 62 3e 20 6f 72 20 3c 62 3e >.dll</b> or <b> 1410: 2e 73 6f 3c 2f 62 3e 20 73 75 66 66 69 78 2e 20 .so</b> suffix. 1420: 49 66 20 79 6f 75 20 77 69 73 68 20 74 6f 20 64 If you wish to d 1430: 6f 20 73 6f 2c 20 79 6f 75 20 63 61 6e 20 65 76 o so, you can ev 1440: 65 6e 74 75 61 6c 6c 79 20 73 70 65 63 69 66 79 entually specify 1450: 20 74 68 65 20 66 75 6c 6c 20 70 61 74 68 20 6c the full path l 1460: 65 61 64 69 6e 67 20 74 6f 20 74 68 65 20 64 79 eading to the dy 1470: 6e 61 6d 69 63 20 6c 69 62 72 61 72 79 2c 20 74 namic library, t 1480: 68 69 73 20 69 6e 63 6c 75 64 69 6e 67 20 61 6e his including an 1490: 79 20 73 75 66 66 69 78 2e 3c 62 72 3e 0d 0a 41 y suffix.<br>..A 14a0: 6e 79 77 61 79 20 74 68 65 20 64 65 66 61 75 6c nyway the defaul 14b0: 74 20 62 65 68 61 76 69 6f 75 72 20 6f 66 20 3c t behaviour of < 14c0: 62 3e 6c 6f 61 64 5f 65 78 74 65 6e 73 69 6f 6e b>load_extension 14d0: 28 29 3c 2f 62 3e 20 69 73 20 74 68 65 20 6f 6e ()</b> is the on 14e0: 65 20 74 6f 20 73 65 61 72 63 68 20 74 68 65 20 e to search the 14f0: 72 65 71 75 69 72 65 64 20 64 79 6e 61 6d 69 63 required dynamic 1500: 20 6c 69 62 72 61 72 79 20 66 6f 6c 6c 6f 77 69 library followi 1510: 6e 67 20 74 68 65 20 73 74 61 6e 64 61 72 64 20 ng the standard 1520: 70 6c 61 74 66 6f 72 6d 20 73 70 65 63 69 66 69 platform specifi 1530: 63 20 72 75 6c 65 73 2e 0d 0a 3c 2f 6c 69 3e 0d c rules...</li>. 1540: 0a 3c 6c 69 3e 54 68 65 20 64 79 6e 61 6d 69 63 .<li>The dynamic 1550: 20 6c 69 62 72 61 72 79 20 69 74 73 65 6c 66 20 library itself 1560: 63 6f 75 6c 64 20 62 65 20 63 6f 72 72 65 63 74 could be correct 1570: 6c 79 20 6c 6f 63 61 74 65 64 2c 20 62 75 74 20 ly located, but 1580: 73 6f 6d 65 20 66 75 72 74 68 65 72 20 64 65 70 some further dep 1590: 65 6e 64 69 6e 67 20 6c 69 62 72 61 72 79 20 63 ending library c 15a0: 6f 75 6c 64 20 6e 6f 74 2c 20 74 68 75 73 20 66 ould not, thus f 15b0: 6f 72 62 69 64 64 69 6e 67 20 74 6f 20 6c 6f 61 orbidding to loa 15c0: 64 20 74 68 65 20 6d 61 69 6e 20 6c 69 62 72 61 d the main libra 15d0: 72 79 2e 3c 62 72 3e 0d 0a 3c 75 3e 50 6c 65 61 ry.<br>..<u>Plea 15e0: 73 65 20 6e 6f 74 65 3c 2f 75 3e 3a 20 3c 62 3e se note</u>: <b> 15f0: 56 69 72 74 75 61 6c 50 47 3c 2f 62 3e 20 64 65 VirtualPG</b> de 1600: 70 65 6e 64 73 20 6f 6e 20 74 68 65 20 50 6f 73 pends on the Pos 1610: 74 67 72 65 53 51 4c 20 6f 77 6e 20 63 6c 69 65 tgreSQL own clie 1620: 6e 74 20 6c 69 62 72 61 72 79 20 28 3c 62 3e 6c nt library (<b>l 1630: 69 62 70 71 3c 2f 62 3e 29 2e 3c 2f 6c 69 3e 0d ibpq</b>).</li>. 1640: 0a 3c 6c 69 3e 49 6e 20 61 6e 79 20 63 61 73 65 .<li>In any case 1650: 2c 20 69 66 20 79 6f 75 20 61 72 65 20 75 73 69 , if you are usi 1660: 6e 67 20 73 6f 6d 65 20 69 6e 74 65 72 61 63 74 ng some interact 1670: 69 76 65 20 74 6f 6f 6c 20 73 75 63 68 20 61 73 ive tool such as 1680: 20 3c 62 3e 73 71 6c 69 74 65 33 3c 2f 62 3e 2c <b>sqlite3</b>, 1690: 20 3c 62 3e 73 70 61 74 69 61 6c 69 74 65 3c 2f <b>spatialite</ 16a0: 62 3e 20 6f 72 20 3c 62 3e 73 70 61 74 69 61 6c b> or <b>spatial 16b0: 69 74 65 5f 67 75 69 3c 2f 62 3e 20 73 6f 6d 65 ite_gui</b> some 16c0: 20 75 73 65 66 75 6c 20 61 6e 64 20 6d 65 61 6e useful and mean 16d0: 69 6e 67 66 75 6c 20 65 72 72 6f 72 20 6d 65 73 ingful error mes 16e0: 73 61 67 65 20 77 69 6c 6c 20 73 75 72 65 6c 79 sage will surely 16f0: 20 62 65 20 64 69 73 70 6c 61 79 65 64 20 65 78 be displayed ex 1700: 70 6c 61 69 6e 69 6e 67 20 74 68 65 20 66 61 69 plaining the fai 1710: 6c 75 72 65 20 63 61 75 73 65 2e 3c 62 72 3e 0d lure cause.<br>. 1720: 0a 54 68 69 73 20 63 6f 75 6c 64 20 6e 6f 74 20 .This could not 1730: 62 65 20 73 75 70 70 6f 72 74 65 64 20 77 68 69 be supported whi 1740: 6c 65 20 61 74 74 65 6d 70 74 69 6e 67 20 74 6f le attempting to 1750: 20 6c 6f 61 64 20 61 6e 20 65 78 74 65 6e 73 69 load an extensi 1760: 6f 6e 20 66 72 6f 6d 20 73 6f 6d 65 20 6c 61 6e on from some lan 1770: 67 75 61 67 65 20 62 69 6e 64 69 6e 67 20 28 65 guage binding (e 1780: 2e 67 2e 20 3c 62 3e 2e 4e 45 54 3c 2f 62 3e 2c .g. <b>.NET</b>, 1790: 20 3c 62 3e 50 79 74 68 6f 6e 3c 2f 62 3e 20 6f <b>Python</b> o 17a0: 72 20 3c 62 3e 4a 61 76 61 3c 2f 62 3e 29 2e 0d r <b>Java</b>).. 17b0: 0a 49 6e 20 74 68 69 73 20 63 61 73 65 20 61 74 .In this case at 17c0: 74 65 6d 70 74 69 6e 67 20 74 6f 20 69 64 65 6e tempting to iden 17d0: 74 69 66 79 20 74 68 65 20 72 65 61 6c 20 65 72 tify the real er 17e0: 72 6f 72 20 63 61 75 73 65 20 63 6f 75 6c 64 20 ror cause could 17f0: 62 65 20 72 65 61 6c 6c 79 20 70 61 69 6e 66 75 be really painfu 1800: 6c 20 64 75 65 20 74 6f 20 70 6f 6f 72 20 61 6e l due to poor an 1810: 64 20 73 6c 6f 70 70 79 20 64 69 61 67 6e 6f 73 d sloppy diagnos 1820: 74 69 63 20 73 75 70 70 6f 72 74 2e 3c 2f 6c 69 tic support.</li 1830: 3e 0d 0a 3c 6c 69 3e 54 68 65 72 65 20 61 72 65 >..<li>There are 1840: 20 6e 6f 20 75 6e 69 76 65 72 73 61 6c 20 72 75 no universal ru 1850: 6c 65 73 20 64 69 63 74 61 74 69 6e 67 20 77 68 les dictating wh 1860: 65 72 65 20 74 6f 20 70 6c 61 63 65 20 79 6f 75 ere to place you 1870: 72 20 65 78 74 65 6e 73 69 6f 6e 20 6d 6f 64 75 r extension modu 1880: 6c 65 73 3b 20 61 20 67 6f 6f 64 20 73 75 67 67 les; a good sugg 1890: 65 73 74 69 6f 6e 20 69 73 20 74 6f 20 61 6c 77 estion is to alw 18a0: 61 79 73 20 70 6c 61 63 65 20 61 6c 6c 20 74 68 ays place all th 18b0: 65 6d 20 69 6e 20 74 68 65 20 6d 6f 73 74 20 61 em in the most a 18c0: 70 70 72 6f 70 72 69 61 74 65 20 73 79 73 74 65 ppropriate syste 18d0: 6d 20 64 69 72 65 63 74 6f 72 79 2e 3c 2f 6c 69 m directory.</li 18e0: 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 62 3e 49 6d 70 >..</ul>..<b>Imp 18f0: 6f 72 74 61 6e 74 20 6e 6f 74 69 63 65 3c 2f 62 ortant notice</b 1900: 3e 3a 20 74 68 65 20 76 65 72 79 20 72 65 63 65 >: the very rece 1910: 6e 74 20 53 51 4c 69 74 65 20 3c 62 3e 33 2e 37 nt SQLite <b>3.7 1920: 2e 31 37 3c 2f 62 3e 20 69 6e 74 72 6f 64 75 63 .17</b> introduc 1930: 65 64 20 6d 61 6e 79 20 69 6e 74 65 72 65 73 74 ed many interest 1940: 69 6e 67 20 61 64 76 61 6e 63 65 64 20 66 65 61 ing advanced fea 1950: 74 75 72 65 73 20 74 6f 20 3c 62 3e 6c 6f 61 64 tures to <b>load 1960: 5f 65 78 74 65 6e 73 69 6f 6e 28 29 3c 2f 62 3e _extension()</b> 1970: 3b 0d 0a 65 61 72 6c 69 65 72 20 76 65 72 73 69 ;..earlier versi 1980: 6f 6e 73 20 6f 66 20 53 51 4c 69 74 65 20 63 6f ons of SQLite co 1990: 75 6c 64 20 70 72 6f 62 61 62 6c 79 20 62 65 20 uld probably be 19a0: 73 6f 6d 65 77 61 79 20 6c 69 6d 69 74 65 64 2e someway limited. 19b0: 0d 0a 49 66 20 74 68 69 73 20 69 73 20 79 6f 75 ..If this is you 19c0: 72 20 63 61 73 65 2c 20 70 6c 65 61 73 65 20 63 r case, please c 19d0: 6f 6e 73 69 64 65 72 20 74 68 61 74 3a 0d 0a 3c onsider that:..< 19e0: 75 6c 3e 0d 0a 3c 6c 69 3e 73 70 65 63 69 66 79 ul>..<li>specify 19f0: 69 6e 67 20 61 6e 79 20 3c 62 3e 2e 64 6c 6c 3c ing any <b>.dll< 1a00: 2f 62 3e 2c 20 3c 62 3e 2e 73 6f 3c 2f 62 3e 20 /b>, <b>.so</b> 1a10: 6f 72 20 3c 62 3e 2e 64 79 6c 69 62 3c 2f 62 3e or <b>.dylib</b> 1a20: 20 73 75 66 66 69 78 20 63 6f 75 6c 64 20 62 65 suffix could be 1a30: 20 73 74 72 69 63 74 6c 79 20 72 65 71 75 69 72 strictly requir 1a40: 65 64 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 73 ed.</li>..<li>as 1a50: 20 69 74 20 63 6f 75 6c 64 20 62 65 20 72 65 71 it could be req 1a60: 75 69 72 65 64 20 74 6f 20 65 78 70 6c 69 63 69 uired to explici 1a70: 74 6c 79 20 73 70 65 63 69 66 79 20 74 68 65 20 tly specify the 1a80: 65 78 74 65 6e 73 69 6f 6e 20 65 6e 74 72 79 20 extension entry 1a90: 70 6f 69 6e 74 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 point.</li>..<li 1aa0: 3e 61 63 63 6f 72 64 69 6e 67 6c 79 20 74 6f 20 >accordingly to 1ab0: 61 6c 6c 20 74 68 69 73 2c 20 79 6f 75 27 6c 6c all this, you'll 1ac0: 20 70 72 6f 62 61 62 6c 79 20 62 65 20 72 65 71 probably be req 1ad0: 75 69 72 65 64 20 74 6f 20 70 61 73 73 20 61 72 uired to pass ar 1ae0: 67 75 6d 65 6e 74 73 20 6c 69 6b 65 20 74 6f 20 guments like to 1af0: 66 6f 6c 6c 6f 77 69 6e 67 20 6f 6e 65 73 20 74 following ones t 1b00: 6f 20 3c 62 3e 6c 6f 61 64 5f 65 78 74 65 6e 73 o <b>load_extens 1b10: 69 6f 6e 28 29 3c 2f 62 3e 20 77 68 69 6c 65 20 ion()</b> while 1b20: 75 73 69 6e 67 20 73 6f 6d 65 20 6f 62 73 6f 6c using some obsol 1b30: 65 74 65 20 53 51 4c 69 74 65 33 20 76 65 72 73 ete SQLite3 vers 1b40: 69 6f 6e 2e 3c 2f 6c 69 3e 0d 0a 3c 76 65 72 62 ion.</li>..<verb 1b50: 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 6c 6f atim>..SELECT lo 1b60: 61 64 5f 65 78 74 65 6e 73 69 6f 6e 28 27 2f 75 ad_extension('/u 1b70: 73 72 2f 6c 6f 63 61 6c 2f 6c 69 62 2f 6d 6f 64 sr/local/lib/mod 1b80: 5f 76 69 72 74 75 61 6c 70 67 2e 73 6f 27 2c 20 _virtualpg.so', 1b90: 27 73 71 6c 69 74 65 33 5f 76 69 72 74 75 61 6c 'sqlite3_virtual 1ba0: 70 67 5f 69 6e 69 74 27 29 3b 0d 0a 2d 2d 2d 2d pg_init');..---- 1bb0: 2d 2d 0d 0a 4e 55 4c 4c 0d 0a 3c 2f 76 65 72 62 --..NULL..</verb 1bc0: 61 74 69 6d 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 2f atim>..</ul>..</ 1bd0: 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 2f 74 61 62 6c td></tr>..</tabl 1be0: 65 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c 68 e><br>..<hr>..<h 1bf0: 33 3e 63 72 6f 73 73 2d 44 42 4d 53 20 64 61 74 3>cross-DBMS dat 1c00: 61 20 65 78 63 68 61 6e 67 65 3a 20 53 51 4c 20 a exchange: SQL 1c10: 61 6e 64 20 56 69 72 74 75 61 6c 50 6f 73 74 67 and VirtualPostg 1c20: 72 65 73 20 74 61 62 6c 65 73 3c 2f 68 33 3e 0d res tables</h3>. 1c30: 0a 41 66 74 65 72 20 73 75 63 63 65 73 73 66 75 .After successfu 1c40: 6c 6c 79 20 6c 6f 61 64 69 6e 67 20 74 68 65 20 lly loading the 1c50: 3c 62 3e 76 69 72 74 75 61 6c 70 67 3c 2f 62 3e <b>virtualpg</b> 1c60: 20 64 79 6e 61 6d 69 63 20 65 78 74 65 6e 73 69 dynamic extensi 1c70: 6f 6e 20 79 6f 75 20 61 72 65 20 6e 6f 77 20 72 on you are now r 1c80: 65 61 64 79 20 74 6f 20 63 72 65 61 74 65 20 3c eady to create < 1c90: 62 3e 56 69 72 74 75 61 6c 50 6f 73 74 67 65 73 b>VirtualPostges 1ca0: 3c 2f 62 3e 20 74 61 62 6c 65 73 2e 3c 62 72 3e </b> tables.<br> 1cb0: 0d 0a 54 68 65 73 65 20 61 72 65 20 3c 69 3e 71 ..These are <i>q 1cc0: 75 69 74 65 20 61 6c 6d 6f 73 74 3c 2f 69 3e 20 uite almost</i> 1cd0: 6f 72 64 69 6e 61 72 79 20 44 42 20 74 61 62 6c ordinary DB tabl 1ce0: 65 73 20 61 73 20 61 6e 79 20 6f 74 68 65 72 3b es as any other; 1cf0: 20 79 6f 75 20 63 61 6e 20 65 78 65 63 75 74 65 you can execute 1d00: 20 61 6e 79 20 72 65 67 75 6c 61 72 20 53 51 4c any regular SQL 1d10: 20 73 74 61 74 65 6d 65 6e 74 20 28 3c 69 3e 53 statement (<i>S 1d20: 45 4c 45 43 54 3c 2f 69 3e 2c 20 3c 69 3e 49 4e ELECT</i>, <i>IN 1d30: 53 45 52 54 3c 2f 69 3e 2c 20 3c 69 3e 55 50 44 SERT</i>, <i>UPD 1d40: 41 54 45 3c 2f 69 3e 20 6f 72 20 3c 69 3e 44 45 ATE</i> or <i>DE 1d50: 4c 45 54 45 3c 2f 69 3e 29 20 62 79 20 73 70 65 LETE</i>) by spe 1d60: 63 69 66 79 69 6e 67 20 74 68 65 73 65 20 56 69 cifying these Vi 1d70: 72 74 75 61 6c 20 54 61 62 6c 65 73 20 61 73 20 rtual Tables as 1d80: 74 68 65 20 73 65 6c 65 63 74 65 64 20 74 61 72 the selected tar 1d90: 67 65 74 2e 3c 62 72 3e 0d 0a 54 68 65 72 65 20 get.<br>..There 1da0: 69 73 20 6f 6e 6c 79 20 61 20 73 74 72 6f 6e 67 is only a strong 1db0: 20 64 69 66 66 65 72 65 6e 63 65 20 64 69 73 74 difference dist 1dc0: 69 6e 67 75 69 73 68 69 6e 67 20 61 20 3c 62 3e inguishing a <b> 1dd0: 56 69 72 74 75 61 6c 50 6f 73 74 67 72 65 73 3c VirtualPostgres< 1de0: 2f 62 3e 20 74 61 62 6c 65 3b 20 69 74 27 73 20 /b> table; it's 1df0: 70 68 79 73 69 63 61 6c 20 6c 6f 63 61 74 69 6f physical locatio 1e00: 6e 20 69 73 6e 27 74 20 77 69 74 68 69 6e 20 74 n isn't within t 1e10: 68 65 20 63 75 72 72 65 6e 74 6c 79 20 63 6f 6e he currently con 1e20: 6e 65 63 74 65 64 20 53 51 4c 69 74 65 20 44 42 nected SQLite DB 1e30: 2c 20 62 75 74 20 69 73 20 69 6e 73 74 65 61 64 , but is instead 1e40: 20 77 69 74 68 69 6e 20 73 6f 6d 65 20 3c 62 3e within some <b> 1e50: 50 6f 73 74 67 72 65 53 51 4c 3c 2f 62 3e 20 44 PostgreSQL</b> D 1e60: 42 4d 53 2e 3c 62 72 3e 0d 0a 53 6f 20 61 20 56 BMS.<br>..So a V 1e70: 69 72 74 75 61 6c 50 6f 73 74 67 72 65 73 20 74 irtualPostgres t 1e80: 61 62 6c 65 20 65 66 66 65 63 74 69 76 65 6c 79 able effectively 1e90: 20 61 63 74 73 20 61 73 20 61 20 3c 69 3e 62 72 acts as a <i>br 1ea0: 69 64 67 65 3c 2f 69 3e 20 6a 6f 69 6e 69 6e 67 idge</i> joining 1eb0: 20 53 51 4c 69 74 65 20 61 6e 64 20 50 6f 73 74 SQLite and Post 1ec0: 67 72 65 73 2c 20 61 6e 64 20 61 6c 6c 6f 77 69 gres, and allowi 1ed0: 6e 67 20 74 6f 20 70 65 72 66 6f 72 6d 20 61 6e ng to perform an 1ee0: 79 20 6b 69 6e 64 20 6f 66 20 63 72 6f 73 73 20 y kind of cross 1ef0: 64 61 74 61 20 65 78 63 68 61 6e 67 65 20 28 3c data exchange (< 1f00: 69 3e 69 6e 20 62 6f 74 68 20 64 69 72 65 63 74 i>in both direct 1f10: 69 6f 6e 73 3c 2f 69 3e 29 20 69 6e 20 74 68 65 ions</i>) in the 1f20: 20 65 61 73 69 65 73 74 20 77 61 79 2e 0d 0a 3c easiest way...< 1f30: 76 65 72 62 61 74 69 6d 3e 0d 0a 43 52 45 41 54 verbatim>..CREAT 1f40: 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 E VIRTUAL TABLE 1f50: 70 67 5f 69 6e 20 0d 0a 20 20 20 20 55 53 49 4e pg_in .. USIN 1f60: 47 20 56 69 72 74 75 61 6c 50 6f 73 74 67 72 65 G VirtualPostgre 1f70: 73 20 28 27 68 6f 73 74 3d 6c 6f 63 61 6c 68 6f s ('host=localho 1f80: 73 74 20 70 6f 72 74 3d 35 34 33 32 20 64 62 6e st port=5432 dbn 1f90: 61 6d 65 3d 67 69 73 20 75 73 65 72 3d 73 61 6e ame=gis user=san 1fa0: 64 72 6f 20 70 61 73 73 77 6f 72 64 3d 73 65 63 dro password=sec 1fb0: 72 65 74 27 2c 20 6d 79 5f 73 63 68 65 6d 61 2c ret', my_schema, 1fc0: 20 6d 79 5f 74 61 62 6c 65 29 3b 0d 0a 3c 2f 76 my_table);..</v 1fd0: 65 72 62 61 74 69 6d 3e 0d 0a 54 68 69 73 20 53 erbatim>..This S 1fe0: 51 4c 20 73 74 61 74 65 6d 65 6e 74 20 77 69 6c QL statement wil 1ff0: 6c 20 63 72 65 61 74 65 20 69 6e 74 6f 20 74 68 l create into th 2000: 65 20 53 51 4c 69 74 65 20 44 42 20 61 20 74 61 e SQLite DB a ta 2010: 62 6c 65 20 6e 61 6d 65 64 20 3c 62 3e 70 67 5f ble named <b>pg_ 2020: 69 6e 3c 2f 62 3e 3b 20 61 6e 79 77 61 79 20 74 in</b>; anyway t 2030: 68 65 20 64 61 74 61 20 70 68 79 73 69 63 61 6c he data physical 2040: 20 73 74 6f 72 61 67 65 20 66 6f 72 20 74 68 69 storage for thi 2050: 73 20 74 61 62 6c 65 20 77 69 6c 6c 20 62 65 20 s table will be 2060: 69 6e 74 6f 20 74 68 65 20 50 6f 73 74 67 72 65 into the Postgre 2070: 73 20 44 42 4d 53 3a 0d 0a 3c 75 6c 3e 0d 0a 3c s DBMS:..<ul>..< 2080: 6c 69 3e 74 68 65 20 66 69 72 73 74 20 61 72 67 li>the first arg 2090: 75 6d 65 6e 74 20 74 6f 20 56 69 72 74 75 61 6c ument to Virtual 20a0: 50 6f 73 74 67 72 65 73 20 69 73 20 74 68 65 20 Postgres is the 20b0: 3c 69 3e 63 6f 6e 6e 65 63 74 69 6f 6e 20 73 74 <i>connection st 20c0: 72 69 6e 67 3c 2f 69 3e 20 72 65 71 75 69 72 65 ring</i> require 20d0: 64 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 65 73 d in order to es 20e0: 74 61 62 6c 69 73 68 20 61 20 63 6f 6e 6e 65 63 tablish a connec 20f0: 74 69 6f 6e 20 74 6f 20 74 68 65 20 50 6f 73 74 tion to the Post 2100: 67 72 65 73 20 44 42 4d 53 20 73 65 72 76 65 72 gres DBMS server 2110: 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 73 65 63 6f .</li>..<li>seco 2120: 6e 64 20 61 6e 64 20 74 68 69 72 64 20 61 72 67 nd and third arg 2130: 75 6d 65 6e 74 73 20 72 65 73 70 65 63 74 69 76 uments respectiv 2140: 65 6c 79 20 61 72 65 20 74 68 65 20 3c 69 3e 73 ely are the <i>s 2150: 63 68 65 6d 61 20 6e 61 6d 65 3c 2f 69 3e 20 61 chema name</i> a 2160: 6e 64 20 74 68 65 20 3c 69 3e 74 61 62 6c 65 20 nd the <i>table 2170: 6e 61 6d 65 3c 2f 69 3e 20 69 64 65 6e 74 69 66 name</i> identif 2180: 79 69 6e 67 20 74 68 65 20 50 6f 73 74 67 72 65 ying the Postgre 2190: 73 20 74 61 72 67 65 74 20 74 61 62 6c 65 2e 3c s target table.< 21a0: 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 76 65 /li>..</ul>..<ve 21b0: 72 62 61 74 69 6d 3e 0d 0a 43 52 45 41 54 45 20 rbatim>..CREATE 21c0: 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 70 67 VIRTUAL TABLE pg 21d0: 5f 69 6e 20 0d 0a 20 20 20 20 55 53 49 4e 47 20 _in .. USING 21e0: 56 69 72 74 75 61 6c 50 6f 73 74 67 72 65 73 20 VirtualPostgres 21f0: 28 27 68 6f 73 74 61 64 64 72 3d 31 39 32 2e 31 ('hostaddr=192.1 2200: 36 38 2e 31 2e 39 31 20 70 6f 72 74 3d 35 34 33 68.1.91 port=543 2210: 32 20 64 62 6e 61 6d 65 3d 67 69 73 20 75 73 65 2 dbname=gis use 2220: 72 3d 73 61 6e 64 72 6f 20 70 61 73 73 77 6f 72 r=sandro passwor 2230: 64 3d 73 65 63 72 65 74 27 2c 20 6d 79 5f 73 63 d=secret', my_sc 2240: 68 65 6d 61 2c 20 6d 79 5f 74 61 62 6c 65 29 3b hema, my_table); 2250: 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 53 ..</verbatim>..S 2260: 61 6d 65 20 61 73 20 61 62 6f 76 65 2c 20 74 68 ame as above, th 2270: 65 20 74 69 6d 65 20 65 73 74 61 62 6c 69 73 68 e time establish 2280: 69 6e 67 20 61 20 63 6f 6e 6e 65 63 74 69 6f 6e ing a connection 2290: 20 74 6f 20 61 20 50 6f 73 74 67 72 65 73 20 69 to a Postgres i 22a0: 6e 73 74 61 6e 63 65 20 72 75 6e 6e 69 6e 67 20 nstance running 22b0: 6f 6e 20 73 6f 6d 65 20 64 69 66 66 65 72 65 6e on some differen 22c0: 74 20 63 6f 6d 70 75 74 65 72 20 6f 6e 20 74 68 t computer on th 22d0: 65 20 73 61 6d 65 20 6c 6f 63 61 6c 20 61 72 65 e same local are 22e0: 61 20 6e 65 74 77 6f 72 6b 2e 3c 62 72 3e 0d 0a a network.<br>.. 22f0: 50 6c 65 61 73 65 20 63 6f 6e 73 75 6c 74 20 74 Please consult t 2300: 68 65 20 50 6f 73 74 67 72 65 73 20 6f 77 6e 20 he Postgres own 2310: 64 6f 63 75 6d 65 6e 74 61 74 69 6f 6e 20 66 6f documentation fo 2320: 72 20 61 6e 79 20 6f 74 68 65 72 20 64 65 74 61 r any other deta 2330: 69 6c 20 61 62 6f 75 74 20 3c 69 3e 63 6f 6e 6e il about <i>conn 2340: 65 63 74 69 6f 6e 20 73 74 72 69 6e 67 73 3c 2f ection strings</ 2350: 69 3e 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d i>...<verbatim>. 2360: 0a 50 52 41 47 4d 41 20 74 61 62 6c 65 5f 69 6e .PRAGMA table_in 2370: 66 6f 28 70 67 5f 69 6e 29 3b 0d 0a 3c 2f 76 65 fo(pg_in);..</ve 2380: 72 62 61 74 69 6d 3e 0d 0a 59 6f 75 20 63 61 6e rbatim>..You can 2390: 20 65 78 65 63 75 74 65 20 74 68 65 20 61 62 6f execute the abo 23a0: 76 65 20 50 52 41 47 4d 41 20 64 69 72 65 63 74 ve PRAGMA direct 23b0: 69 76 65 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 ive in order to 23c0: 69 64 65 6e 74 69 66 79 20 61 6c 6c 20 63 6f 6c identify all col 23d0: 75 6d 6e 73 20 64 65 63 6c 61 72 65 64 20 62 79 umns declared by 23e0: 20 74 68 65 20 50 6f 73 74 67 72 65 73 20 74 61 the Postgres ta 23f0: 62 6c 65 2c 20 61 6e 64 20 74 68 65 69 72 20 63 ble, and their c 2400: 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 64 61 74 orresponding dat 2410: 61 2d 74 79 70 65 2e 3c 62 72 3e 0d 0a 49 66 20 a-type.<br>..If 2420: 79 6f 75 20 61 72 65 20 61 63 74 75 61 6c 6c 79 you are actually 2430: 20 75 73 69 6e 67 20 3c 62 3e 73 70 61 74 69 61 using <b>spatia 2440: 6c 69 74 65 5f 67 75 69 3c 2f 62 3e 20 79 6f 75 lite_gui</b> you 2450: 20 63 61 6e 20 63 68 65 63 6b 20 74 68 65 20 73 can check the s 2460: 61 6d 65 20 69 6e 66 6f 73 20 62 79 20 75 73 69 ame infos by usi 2470: 6e 67 20 74 68 65 20 61 70 70 72 6f 70 72 69 61 ng the appropria 2480: 74 65 20 67 72 61 70 68 69 63 73 20 74 6f 6f 6c te graphics tool 2490: 73 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a s...<verbatim>.. 24a0: 53 45 4c 45 43 54 20 61 2c 20 62 2c 20 63 2c 20 SELECT a, b, c, 24b0: 43 6f 75 6e 74 28 2a 29 20 41 53 20 63 6e 74 0d Count(*) AS cnt. 24c0: 0a 46 52 4f 4d 20 70 67 5f 69 6e 0d 0a 57 48 45 .FROM pg_in..WHE 24d0: 52 45 20 65 20 49 53 20 4e 4f 54 20 4e 55 4c 4c RE e IS NOT NULL 24e0: 0d 0a 47 52 4f 55 50 20 42 59 20 61 2c 20 62 2c ..GROUP BY a, b, 24f0: 20 63 0d 0a 4f 52 44 45 52 20 42 59 20 63 6e 74 c..ORDER BY cnt 2500: 20 44 45 53 43 3b 0d 0a 3c 2f 76 65 72 62 61 74 DESC;..</verbat 2510: 69 6d 3e 0d 0a 59 6f 75 20 63 61 6e 20 65 78 65 im>..You can exe 2520: 63 75 74 65 20 61 6e 79 20 6b 69 6e 64 20 6f 66 cute any kind of 2530: 20 3c 62 3e 53 45 4c 45 43 54 3c 2f 62 3e 20 71 <b>SELECT</b> q 2540: 75 65 72 79 20 75 73 69 6e 67 20 61 20 56 69 72 uery using a Vir 2550: 74 75 61 6c 50 6f 73 74 67 72 65 73 20 74 61 62 tualPostgres tab 2560: 6c 65 2c 20 65 78 61 63 74 6c 79 20 61 73 20 69 le, exactly as i 2570: 66 20 69 74 20 77 61 73 20 61 20 67 65 6e 75 69 f it was a genui 2580: 6e 65 20 6e 61 74 69 76 65 20 74 61 62 6c 65 2e ne native table. 2590: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 43 52 ..<verbatim>..CR 25a0: 45 41 54 45 20 54 41 42 4c 45 20 69 6d 70 6f 72 EATE TABLE impor 25b0: 74 65 64 5f 66 72 6f 6d 5f 70 67 20 41 53 0d 0a ted_from_pg AS.. 25c0: 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 70 67 SELECT * FROM pg 25d0: 5f 69 6e 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d _in;..</verbatim 25e0: 3e 0d 0a 41 6e 64 20 79 6f 75 20 63 61 6e 20 6f >..And you can o 25f0: 62 76 69 6f 75 73 6c 79 20 63 72 65 61 74 65 20 bviously create 2600: 61 6e 64 20 70 6f 70 75 6c 61 74 65 20 61 20 6c and populate a l 2610: 6f 63 61 6c 20 63 6f 70 79 20 6f 66 20 74 68 65 ocal copy of the 2620: 20 72 65 6d 6f 74 65 20 50 6f 73 74 67 72 65 73 remote Postgres 2630: 20 74 61 62 6c 65 3a 20 6e 6f 77 20 61 6c 6c 20 table: now all 2640: 64 61 74 61 20 61 72 65 20 70 65 72 6d 61 6e 65 data are permane 2650: 6e 74 6c 79 20 73 74 6f 72 65 64 20 77 69 74 68 ntly stored with 2660: 69 6e 20 79 6f 75 72 20 53 51 4c 69 74 65 20 44 in your SQLite D 2670: 42 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a B...<verbatim>.. 2680: 44 52 4f 50 20 54 41 42 4c 45 20 70 67 5f 69 6e DROP TABLE pg_in 2690: 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a ;..</verbatim>.. 26a0: 53 6f 20 79 6f 75 20 63 61 6e 20 66 69 6e 61 6c So you can final 26b0: 6c 79 20 64 72 6f 70 20 74 68 65 20 56 69 72 74 ly drop the Virt 26c0: 75 61 6c 50 6f 73 74 67 72 65 73 20 74 61 62 6c ualPostgres tabl 26d0: 65 2c 20 61 6e 64 20 74 68 69 73 20 77 69 6c 6c e, and this will 26e0: 20 69 6d 6d 65 64 69 61 74 65 6c 79 20 74 65 72 immediately ter 26f0: 6d 69 6e 61 74 65 20 74 68 65 20 63 6f 6e 6e 65 minate the conne 2700: 63 74 69 6f 6e 20 74 6f 20 74 68 65 20 50 6f 73 ction to the Pos 2710: 74 67 72 65 73 20 44 42 4d 53 2e 3c 62 72 3e 3c tgres DBMS.<br>< 2720: 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c 68 33 3e 64 br>..<hr>..<h3>d 2730: 61 74 61 2d 74 79 70 65 20 6d 61 70 70 69 6e 67 ata-type mapping 2740: 20 61 6e 64 20 72 65 6c 61 74 65 64 20 63 6f 6e and related con 2750: 76 65 72 73 69 6f 6e 73 3c 2f 68 33 3e 0d 0a 52 versions</h3>..R 2760: 61 74 68 65 72 20 6f 62 76 69 6f 75 73 6c 79 20 ather obviously 2770: 53 51 4c 69 74 65 20 61 6e 64 20 50 6f 73 74 67 SQLite and Postg 2780: 72 65 73 20 73 75 70 70 6f 72 74 73 20 76 65 72 res supports ver 2790: 79 20 64 69 66 66 65 72 65 6e 74 20 6b 69 6e 64 y different kind 27a0: 20 6f 66 20 64 61 74 61 2d 74 79 70 65 73 2e 20 of data-types. 27b0: 54 68 65 20 66 65 77 20 66 6f 6c 6c 6f 77 69 6e The few followin 27c0: 67 20 72 75 6c 65 73 20 61 70 70 6c 79 3a 0d 0a g rules apply:.. 27d0: 3c 75 6c 3e 0d 0a 3c 6c 69 3e 61 6e 79 20 6b 69 <ul>..<li>any ki 27e0: 6e 64 20 6f 66 20 3c 62 3e 49 4e 54 45 47 45 52 nd of <b>INTEGER 27f0: 3c 2f 62 3e 20 76 61 6c 75 65 20 69 73 20 70 72 </b> value is pr 2800: 65 73 65 72 76 65 64 20 61 73 20 73 75 63 68 2e eserved as such. 2810: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 74 68 65 20 73 </li>..<li>the s 2820: 61 6d 65 20 69 73 20 66 6f 72 20 3c 62 3e 46 4c ame is for <b>FL 2830: 4f 41 54 3c 2f 62 3e 20 76 61 6c 75 65 73 2e 3c OAT</b> values.< 2840: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 4d 4f 4e /li>..<li><b>MON 2850: 45 59 3c 2f 62 3e 20 61 6e 64 20 3c 62 3e 4e 55 EY</b> and <b>NU 2860: 4d 45 52 49 43 3c 2f 62 3e 20 76 61 6c 75 65 73 MERIC</b> values 2870: 20 61 72 65 20 63 6f 6e 76 65 72 74 65 64 20 69 are converted i 2880: 6e 74 6f 20 3c 62 3e 46 4c 4f 41 54 3c 2f 62 3e nto <b>FLOAT</b> 2890: 20 76 61 6c 75 65 73 2e 3c 2f 6c 69 3e 0d 0a 3c values.</li>..< 28a0: 6c 69 3e 3c 62 3e 43 48 41 52 3c 2f 62 3e 20 61 li><b>CHAR</b> a 28b0: 6e 64 20 3c 62 3e 56 41 52 43 48 41 52 3c 2f 62 nd <b>VARCHAR</b 28c0: 3e 20 76 61 6c 75 65 73 20 61 72 65 20 61 6c 77 > values are alw 28d0: 61 79 73 20 63 6f 6e 76 65 72 74 65 64 20 69 6e ays converted in 28e0: 74 6f 20 3c 62 3e 54 45 58 54 3c 2f 62 3e 20 76 to <b>TEXT</b> v 28f0: 61 6c 75 65 73 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 alues.</li>..<li 2900: 3e 3c 62 3e 44 41 54 45 3c 2f 62 3e 2c 20 3c 62 ><b>DATE</b>, <b 2910: 3e 54 49 4d 45 3c 2f 62 3e 20 61 6e 64 20 3c 62 >TIME</b> and <b 2920: 3e 54 49 4d 45 53 54 41 4d 50 3c 2f 62 3e 20 76 >TIMESTAMP</b> v 2930: 61 6c 75 65 73 20 61 72 65 20 61 6c 77 61 79 73 alues are always 2940: 20 63 6f 6e 76 65 72 74 65 64 20 69 6e 74 6f 20 converted into 2950: 3c 62 3e 46 4c 4f 41 54 3c 2f 62 3e 20 76 61 6c <b>FLOAT</b> val 2960: 75 65 73 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e ues correspondin 2970: 67 20 74 6f 20 74 68 65 20 3c 61 20 68 72 65 66 g to the <a href 2980: 3d 22 68 74 74 70 3a 2f 2f 77 77 77 2e 73 71 6c ="http://www.sql 2990: 69 74 65 2e 6f 72 67 2f 6c 61 6e 67 5f 64 61 74 ite.org/lang_dat 29a0: 65 66 75 6e 63 2e 68 74 6d 6c 22 3e 4a 75 6c 69 efunc.html">Juli 29b0: 61 6e 44 61 79 3c 2f 61 3e 20 6e 6f 74 61 74 69 anDay</a> notati 29c0: 6f 6e 20 73 75 70 70 6f 72 74 65 64 20 62 79 20 on supported by 29d0: 53 51 4c 69 74 65 2e 3c 62 72 3e 0d 0a 59 6f 75 SQLite.<br>..You 29e0: 20 63 61 6e 20 74 68 65 6e 20 69 6e 76 6f 6b 65 can then invoke 29f0: 20 74 68 65 20 61 70 70 72 6f 70 72 69 61 74 65 the appropriate 2a00: 20 66 75 6e 63 74 69 6f 6e 20 62 65 74 77 65 65 function betwee 2a10: 6e 20 3c 62 3e 44 61 74 65 28 29 3c 2f 62 3e 2c n <b>Date()</b>, 2a20: 20 3c 62 3e 54 69 6d 65 28 29 3c 2f 62 3e 20 6f <b>Time()</b> o 2a30: 72 20 3c 62 3e 44 61 74 65 54 69 6d 65 28 29 3c r <b>DateTime()< 2a40: 2f 62 3e 20 73 6f 20 74 6f 20 67 65 74 20 62 61 /b> so to get ba 2a50: 63 6b 20 74 68 65 20 73 74 61 6e 64 61 72 64 20 ck the standard 2a60: 53 51 4c 20 6e 6f 74 61 74 69 6f 6e 20 66 6f 72 SQL notation for 2a70: 20 64 61 74 65 73 20 61 6e 64 20 74 69 6d 65 73 dates and times 2a80: 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 42 .</li>..<li><b>B 2a90: 4f 4f 4c 3c 2f 62 3e 20 76 61 6c 75 65 73 20 61 OOL</b> values a 2aa0: 72 65 20 61 6c 77 61 79 73 20 63 6f 6e 76 65 72 re always conver 2ab0: 74 65 64 20 69 6e 74 6f 20 3c 62 3e 49 4e 54 45 ted into <b>INTE 2ac0: 47 45 52 3c 2f 62 3e 20 76 61 6c 75 65 73 3a 20 GER</b> values: 2ad0: 3c 62 3e 30 3c 2f 62 3e 20 63 6f 72 72 65 73 70 <b>0</b> corresp 2ae0: 6f 6e 64 69 6e 67 20 74 6f 20 3c 62 3e 46 41 4c onding to <b>FAL 2af0: 53 45 3c 2f 62 3e 2e 3c 2f 6c 69 3e 0d 0a 3c 6c SE</b>.</li>..<l 2b00: 69 3e 50 6f 73 74 67 72 65 73 20 73 75 70 70 6f i>Postgres suppo 2b10: 72 74 73 20 6d 75 6c 74 69 70 6c 65 20 76 61 6c rts multiple val 2b20: 75 65 73 20 74 6f 20 62 65 20 73 74 6f 72 65 64 ues to be stored 2b30: 20 69 6e 74 6f 20 74 68 65 20 73 61 6d 65 20 63 into the same c 2b40: 6f 6c 75 6d 6e 20 28 3c 62 3e 41 52 52 41 59 3c olumn (<b>ARRAY< 2b50: 2f 62 3e 29 3a 20 53 51 4c 69 74 65 20 68 61 73 /b>): SQLite has 2b60: 20 6e 6f 20 73 69 6d 69 6c 61 72 20 63 61 70 61 no similar capa 2b70: 62 69 6c 69 74 79 2c 20 73 6f 20 61 6e 79 20 41 bility, so any A 2b80: 52 52 41 59 20 76 61 6c 75 65 20 77 69 6c 6c 20 RRAY value will 2b90: 73 69 6d 70 6c 79 20 62 65 20 63 6f 6e 76 65 72 simply be conver 2ba0: 74 65 64 20 69 6e 74 6f 20 61 20 3c 62 3e 54 45 ted into a <b>TE 2bb0: 58 54 3c 2f 62 3e 20 73 74 72 69 6e 67 2c 20 65 XT</b> string, e 2bc0: 2e 67 2e 20 61 73 20 69 6e 20 3c 62 3e 27 7b 31 .g. as in <b>'{1 2bd0: 2c 32 2c 33 7d 27 3c 2f 62 3e 20 6f 72 20 3c 62 ,2,3}'</b> or <b 2be0: 3e 27 7b 61 6c 70 68 61 2c 62 65 74 61 2c 67 61 >'{alpha,beta,ga 2bf0: 6d 6d 61 2c 64 65 6c 74 61 7d 27 3c 2f 62 3e 2e mma,delta}'</b>. 2c00: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 6e 79 20 62 </li>..<li>any b 2c10: 69 6e 61 72 79 20 76 61 6c 75 65 20 28 61 73 20 inary value (as 2c20: 65 2e 67 2e 20 3c 62 3e 42 59 54 45 41 3c 2f 62 e.g. <b>BYTEA</b 2c30: 3e 29 20 77 69 6c 6c 20 62 65 20 73 69 6d 70 6c >) will be simpl 2c40: 79 20 63 6f 6e 76 65 72 74 65 64 20 69 6e 74 6f y converted into 2c50: 20 61 20 3c 62 3e 54 45 58 54 3c 2f 62 3e 20 76 a <b>TEXT</b> v 2c60: 61 6c 75 65 20 63 6f 6e 74 61 69 6e 69 6e 67 20 alue containing 2c70: 74 68 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e the correspondin 2c80: 67 20 68 65 78 61 64 65 63 69 6d 61 6c 20 6e 6f g hexadecimal no 2c90: 74 61 74 69 6f 6e 2c 20 65 2e 67 2e 20 61 73 20 tation, e.g. as 2ca0: 69 6e 20 3c 62 3e 27 30 31 30 31 30 30 30 30 32 in <b>'010100002 2cb0: 30 45 38 36 34 30 30 30 30 43 34 46 43 33 34 42 0E8640000C4FC34B 2cc0: 41 38 34 34 38 32 34 34 31 35 30 43 31 42 35 44 A8448244150C1B5D 2cd0: 35 34 31 42 38 35 33 34 31 27 3c 2f 62 3e 2e 3c 541B85341'</b>.< 2ce0: 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 62 72 3e 0d /li>..</ul><br>. 2cf0: 0a 3c 68 72 3e 0d 0a 3c 68 33 3e 68 61 6e 64 6c .<hr>..<h3>handl 2d00: 69 6e 67 20 50 6f 73 74 47 49 53 20 67 65 6f 6d ing PostGIS geom 2d10: 65 74 72 69 65 73 3c 2f 68 33 3e 0d 0a 50 6f 73 etries</h3>..Pos 2d20: 74 47 49 53 20 6f 77 6e 20 67 65 6f 6d 65 74 72 tGIS own geometr 2d30: 69 65 73 20 73 69 6d 70 6c 79 20 61 72 65 20 72 ies simply are r 2d40: 65 70 72 65 73 65 6e 74 65 64 20 62 79 20 61 20 epresented by a 2d50: 3c 62 3e 42 59 54 45 41 3c 2f 62 3e 20 76 61 6c <b>BYTEA</b> val 2d60: 75 65 20 74 6f 20 62 65 20 69 6e 74 65 72 70 72 ue to be interpr 2d70: 65 74 65 64 20 61 63 63 6f 72 64 69 6e 67 6c 79 eted accordingly 2d80: 20 74 6f 20 3c 62 3e 45 57 4b 42 3c 2f 62 3e 20 to <b>EWKB</b> 2d90: 66 6f 72 6d 61 74 20 73 70 65 63 69 66 69 63 61 format specifica 2da0: 74 69 6f 6e 73 2e 0d 0a 3c 76 65 72 62 61 74 69 tions...<verbati 2db0: 6d 3e 0d 0a 43 52 45 41 54 45 20 54 41 42 4c 45 m>..CREATE TABLE 2dc0: 20 66 72 6f 6d 5f 70 6f 73 74 67 69 73 20 41 53 from_postgis AS 2dd0: 0d 0a 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 ..SELECT * FROM 2de0: 70 67 5f 69 6e 3b 0d 0a 0d 0a 55 50 44 41 54 45 pg_in;....UPDATE 2df0: 20 66 72 6f 6d 5f 70 6f 73 74 67 69 73 20 53 45 from_postgis SE 2e00: 54 20 67 65 6f 6d 65 74 72 79 20 3d 20 47 65 6f T geometry = Geo 2e10: 6d 46 72 6f 6d 45 57 4b 42 28 67 65 6f 6d 65 74 mFromEWKB(geomet 2e20: 72 79 29 3b 0d 0a 0d 0a 53 45 4c 45 43 54 20 44 ry);....SELECT D 2e30: 49 53 54 49 4e 43 54 20 53 54 5f 47 65 6f 6d 65 ISTINCT ST_Geome 2e40: 74 72 79 54 79 70 65 28 67 65 6f 6d 65 74 72 79 tryType(geometry 2e50: 29 2c 20 53 54 5f 53 72 69 64 28 67 65 6f 6d 65 ), ST_Srid(geome 2e60: 74 72 79 29 2c 20 43 6f 6f 72 64 44 69 6d 65 6e try), CoordDimen 2e70: 73 69 6f 6e 28 67 65 6f 6d 65 74 72 79 29 0d 0a sion(geometry).. 2e80: 46 52 4f 4d 20 66 72 6f 6d 5f 70 6f 73 74 67 69 FROM from_postgi 2e90: 73 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d s;..------------ 2ea0: 0d 0a 4c 49 4e 45 53 54 52 49 4e 47 7c 32 35 38 ..LINESTRING|258 2eb0: 33 32 7c 58 59 0d 0a 0d 0a 53 45 4c 45 43 54 20 32|XY....SELECT 2ec0: 52 65 63 6f 76 65 72 47 65 6f 6d 65 74 72 79 43 RecoverGeometryC 2ed0: 6f 6c 75 6d 6e 28 27 66 72 6f 6d 5f 70 6f 73 74 olumn('from_post 2ee0: 67 69 73 27 2c 20 27 67 65 6f 6d 65 74 72 79 27 gis', 'geometry' 2ef0: 2c 20 32 35 38 33 32 2c 20 27 4c 49 4e 45 53 54 , 25832, 'LINEST 2f00: 52 49 4e 47 27 2c 20 27 58 59 27 29 3b 0d 0a 2d RING', 'XY');..- 2f10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 31 0d 0a -----------..1.. 2f20: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 54 68 69 </verbatim>..Thi 2f30: 73 20 73 65 71 75 65 6e 63 65 20 6f 66 20 53 51 s sequence of SQ 2f40: 4c 20 73 74 61 74 65 6d 65 6e 74 73 20 28 53 70 L statements (Sp 2f50: 61 74 69 61 4c 69 74 65 20 73 75 70 70 6f 72 74 atiaLite support 2f60: 20 69 73 20 73 74 72 69 63 74 6c 79 20 72 65 71 is strictly req 2f70: 75 69 72 65 64 29 20 77 69 6c 6c 20 74 72 61 6e uired) will tran 2f80: 73 66 65 72 20 61 20 66 75 6c 6c 79 20 71 75 61 sfer a fully qua 2f90: 6c 69 66 69 65 64 20 47 65 6f 6d 65 74 72 79 20 lified Geometry 2fa0: 74 61 62 6c 65 20 66 72 6f 6d 20 50 6f 73 74 47 table from PostG 2fb0: 49 53 20 74 6f 20 53 70 61 74 69 61 4c 69 74 65 IS to SpatiaLite 2fc0: 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 3c 62 3e :..<ul>..<li><b> 2fd0: 73 74 65 70 20 31 3c 2f 62 3e 3a 20 66 69 72 73 step 1</b>: firs 2fe0: 74 20 77 65 27 6c 6c 20 74 72 61 6e 73 66 65 72 t we'll transfer 2ff0: 20 74 68 65 20 77 68 6f 6c 65 20 50 6f 73 74 47 the whole PostG 3000: 49 53 20 74 61 62 6c 65 20 69 6e 74 6f 20 53 51 IS table into SQ 3010: 4c 69 74 65 3b 20 67 65 6f 6d 65 74 72 69 65 73 Lite; geometries 3020: 20 61 72 65 20 73 74 69 6c 6c 20 72 65 70 72 65 are still repre 3030: 73 65 6e 74 65 64 20 62 79 20 74 68 65 69 72 20 sented by their 3040: 3c 62 3e 45 57 4b 42 3c 2f 62 3e 20 68 65 78 61 <b>EWKB</b> hexa 3050: 64 65 63 69 6d 61 6c 20 6e 6f 74 61 74 69 6f 6e decimal notation 3060: 73 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e s.</li>..<li><b> 3070: 73 74 65 70 20 32 3c 2f 62 3e 3a 20 74 68 65 6e step 2</b>: then 3080: 20 77 65 27 6c 6c 20 75 73 65 20 74 68 65 20 3c we'll use the < 3090: 62 3e 47 65 6f 6d 46 72 6f 6d 45 57 4b 42 28 29 b>GeomFromEWKB() 30a0: 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f </b> SQL functio 30b0: 6e 20 73 6f 20 74 6f 20 67 65 74 20 74 68 65 20 n so to get the 30c0: 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 3c 62 corresponding <b 30d0: 3e 53 70 61 74 69 61 4c 69 74 65 27 73 20 42 4c >SpatiaLite's BL 30e0: 4f 42 3c 2f 62 3e 20 66 6f 72 20 65 61 63 68 20 OB</b> for each 30f0: 67 65 6f 6d 65 74 72 79 2e 3c 2f 6c 69 3e 0d 0a geometry.</li>.. 3100: 3c 6c 69 3e 3c 62 3e 73 74 65 70 20 33 3c 2f 62 <li><b>step 3</b 3110: 3e 3a 20 6e 6f 77 20 77 65 20 73 69 6d 70 6c 79 >: now we simply 3120: 20 68 61 76 65 20 74 6f 20 64 69 73 63 6f 76 65 have to discove 3130: 72 20 74 68 65 20 54 79 70 65 2c 20 53 52 49 44 r the Type, SRID 3140: 20 61 6e 64 20 44 69 6d 65 6e 73 69 6f 6e 73 20 and Dimensions 3150: 64 65 63 6c 61 72 65 64 20 62 79 20 74 68 65 73 declared by thes 3160: 65 20 67 65 6f 6d 65 74 72 69 65 73 2e 3c 2f 6c e geometries.</l 3170: 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 73 74 65 70 20 i>..<li><b>step 3180: 34 3c 2f 62 3e 3a 20 61 6e 64 20 66 69 6e 61 6c 4</b>: and final 3190: 6c 79 20 77 65 20 63 61 6e 20 6e 6f 77 20 72 65 ly we can now re 31a0: 63 6f 76 65 72 20 61 20 66 75 6c 6c 20 71 75 61 cover a full qua 31b0: 6c 69 66 69 65 64 20 53 70 61 74 69 61 4c 69 74 lified SpatiaLit 31c0: 65 27 73 20 6f 77 6e 20 28 3c 69 3e 6e 61 74 69 e's own (<i>nati 31d0: 76 65 3c 2f 69 3e 29 20 47 65 6f 6d 65 74 72 79 ve</i>) Geometry 31e0: 20 63 6f 6c 75 6d 6e 2e 3c 2f 6c 69 3e 0d 0a 3c column.</li>..< 31f0: 2f 75 6c 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a /ul><br>..<hr>.. 3200: 3c 68 33 3e 65 78 70 6f 72 74 69 6e 67 20 64 61 <h3>exporting da 3210: 74 61 20 66 72 6f 6d 20 53 51 4c 69 74 65 20 74 ta from SQLite t 3220: 6f 20 50 6f 73 74 67 72 65 73 2f 50 6f 73 74 47 o Postgres/PostG 3230: 49 53 3c 2f 68 33 3e 0d 0a 46 6f 72 20 72 61 74 IS</h3>..For rat 3240: 68 65 72 20 6f 62 76 69 6f 75 73 20 73 65 63 75 her obvious secu 3250: 72 69 74 79 20 72 65 61 73 6f 6e 73 2c 20 61 6c rity reasons, al 3260: 6c 20 56 69 72 74 75 61 6c 50 6f 73 74 67 72 65 l VirtualPostgre 3270: 73 20 74 61 62 6c 65 73 20 61 72 65 20 64 65 63 s tables are dec 3280: 6c 61 72 65 64 20 74 6f 20 62 65 20 3c 69 3e 72 lared to be <i>r 3290: 65 61 64 2d 6f 6e 6c 79 3c 2f 69 3e 20 62 79 20 ead-only</i> by 32a0: 64 65 66 61 75 6c 74 2e 3c 62 72 3e 0d 0a 54 68 default.<br>..Th 32b0: 69 73 20 61 63 74 75 61 6c 6c 79 20 6d 65 61 6e is actually mean 32c0: 73 20 74 68 61 74 20 79 6f 75 20 61 72 65 20 65 s that you are e 32d0: 6e 61 62 6c 65 64 20 74 6f 20 65 78 65 63 75 74 nabled to execut 32e0: 65 20 61 6e 79 20 70 6f 73 73 69 62 6c 65 20 3c e any possible < 32f0: 62 3e 53 45 4c 45 43 54 3c 2f 62 3e 20 71 75 65 b>SELECT</b> que 3300: 72 79 2c 20 62 75 74 20 61 6e 79 20 3c 62 3e 49 ry, but any <b>I 3310: 4e 53 45 52 54 3c 2f 62 3e 2c 20 3c 62 3e 55 50 NSERT</b>, <b>UP 3320: 44 41 54 45 3c 2f 62 3e 20 6f 72 20 3c 62 3e 44 DATE</b> or <b>D 3330: 45 4c 45 54 45 3c 2f 62 3e 20 6f 70 65 72 61 74 ELETE</b> operat 3340: 69 6f 6e 20 61 66 66 65 63 74 69 6e 67 20 74 68 ion affecting th 3350: 65 20 50 6f 73 74 67 72 65 73 20 44 42 4d 53 20 e Postgres DBMS 3360: 69 73 20 73 74 72 69 63 74 6c 79 20 66 6f 72 62 is strictly forb 3370: 69 64 64 65 6e 2e 0d 0a 3c 76 65 72 62 61 74 69 idden...<verbati 3380: 6d 3e 0d 0a 43 52 45 41 54 45 20 56 49 52 54 55 m>..CREATE VIRTU 3390: 41 4c 20 54 41 42 4c 45 20 70 67 5f 6f 75 74 20 AL TABLE pg_out 33a0: 0d 0a 20 20 20 20 55 53 49 4e 47 20 56 69 72 74 .. USING Virt 33b0: 75 61 6c 50 6f 73 74 67 72 65 73 20 28 27 68 6f ualPostgres ('ho 33c0: 73 74 61 64 64 72 3d 31 39 32 2e 31 36 38 2e 31 staddr=192.168.1 33d0: 2e 39 31 20 70 6f 72 74 3d 35 34 33 32 20 64 62 .91 port=5432 db 33e0: 6e 61 6d 65 3d 67 69 73 20 75 73 65 72 3d 73 61 name=gis user=sa 33f0: 6e 64 72 6f 20 70 61 73 73 77 6f 72 64 3d 73 65 ndro password=se 3400: 63 72 65 74 27 2c 20 6d 79 5f 73 63 68 65 6d 61 cret', my_schema 3410: 2c 20 6d 79 5f 74 61 62 6c 65 2c 20 57 29 3b 0d , my_table, W);. 3420: 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 41 6e .</verbatim>..An 3430: 79 77 61 79 20 79 6f 75 20 63 61 6e 20 65 78 70 yway you can exp 3440: 6c 69 63 69 74 6c 79 20 72 65 71 75 65 73 74 20 licitly request 3450: 61 20 56 69 72 74 75 61 6c 50 6f 73 74 67 72 65 a VirtualPostgre 3460: 73 20 74 61 62 6c 65 20 74 6f 20 73 75 70 70 6f s table to suppo 3470: 72 74 20 75 6e 63 6f 6e 73 74 72 61 69 6e 65 64 rt unconstrained 3480: 20 3c 69 3e 72 65 61 64 2d 77 72 69 74 65 3c 2f <i>read-write</ 3490: 69 3e 20 6f 70 65 72 61 74 69 6f 6e 73 2c 20 74 i> operations, t 34a0: 68 69 73 20 69 6e 63 6c 75 64 69 6e 67 20 61 6e his including an 34b0: 79 20 3c 62 3e 49 4e 53 45 52 54 3c 2f 62 3e 2c y <b>INSERT</b>, 34c0: 20 3c 62 3e 55 50 44 41 54 45 3c 2f 62 3e 20 6f <b>UPDATE</b> o 34d0: 72 20 3c 62 3e 44 45 4c 45 54 45 3c 2f 62 3e 20 r <b>DELETE</b> 34e0: 73 74 61 74 65 6d 65 6e 74 20 61 66 66 65 63 74 statement affect 34f0: 69 6e 67 20 74 68 65 20 50 6f 73 74 67 72 65 73 ing the Postgres 3500: 20 44 42 4d 53 2e 3c 62 72 3e 0d 0a 49 6e 20 74 DBMS.<br>..In t 3510: 68 69 73 20 63 61 73 65 20 79 6f 75 20 73 69 6d his case you sim 3520: 70 6c 79 20 68 61 76 65 20 74 6f 20 70 61 73 73 ply have to pass 3530: 20 61 20 66 75 72 74 68 65 72 20 66 6f 75 72 74 a further fourt 3540: 68 20 61 72 67 75 6d 65 6e 74 20 69 6e 74 6f 20 h argument into 3550: 74 68 65 20 3c 62 3e 55 53 49 4e 47 3c 2f 62 3e the <b>USING</b> 3560: 20 63 6c 61 75 73 65 20 65 78 61 63 74 6c 79 20 clause exactly 3570: 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 74 6f corresponding to 3580: 20 74 68 65 20 6c 65 74 74 65 72 20 3c 62 3e 57 the letter <b>W 3590: 3c 2f 62 3e 2e 0d 0a 3c 76 65 72 62 61 74 69 6d </b>...<verbatim 35a0: 3e 0d 0a 44 45 4c 45 54 45 20 46 52 4f 4d 20 70 >..DELETE FROM p 35b0: 67 5f 6f 75 74 3b 0d 0a 0d 0a 49 4e 53 45 52 54 g_out;....INSERT 35c0: 20 49 4e 54 4f 20 70 67 5f 6f 75 74 20 28 66 6c INTO pg_out (fl 35d0: 64 5f 61 2c 20 66 6c 64 5f 62 2c 20 66 6c 64 5f d_a, fld_b, fld_ 35e0: 63 2c 20 67 65 6f 6d 65 74 72 79 29 0d 0a 53 45 c, geometry)..SE 35f0: 4c 45 43 54 20 66 6c 64 5f 61 2c 20 66 6c 64 5f LECT fld_a, fld_ 3600: 62 2c 20 66 6c 64 5f 63 2c 20 41 73 45 57 4b 42 b, fld_c, AsEWKB 3610: 28 67 65 6f 6d 65 74 72 79 29 0d 0a 66 72 6f 6d (geometry)..from 3620: 20 73 6f 6d 65 5f 74 61 62 6c 65 3b 0d 0a 3c 2f some_table;..</ 3630: 76 65 72 62 61 74 69 6d 3e 0d 0a 49 6e 20 74 68 verbatim>..In th 3640: 65 20 61 62 6f 76 65 20 65 78 61 6d 70 6c 65 20 e above example 3650: 77 65 27 6c 6c 20 64 65 6c 65 74 65 20 66 69 72 we'll delete fir 3660: 73 74 20 61 6e 79 20 61 6c 72 65 61 64 79 20 65 st any already e 3670: 78 69 73 74 69 6e 67 20 72 6f 77 20 66 72 6f 6d xisting row from 3680: 20 74 68 65 20 50 6f 73 74 47 49 53 20 74 61 62 the PostGIS tab 3690: 6c 65 3b 20 74 68 65 6e 20 77 65 27 6c 6c 20 73 le; then we'll s 36a0: 69 6d 70 6c 79 20 74 72 61 6e 73 66 65 72 20 74 imply transfer t 36b0: 68 65 20 77 68 6f 6c 65 20 74 61 62 6c 65 20 66 he whole table f 36c0: 72 6f 6d 20 53 70 61 74 69 61 4c 69 74 65 20 69 rom SpatiaLite i 36d0: 6e 74 6f 20 50 6f 73 74 47 49 53 2e 3c 62 72 3e nto PostGIS.<br> 36e0: 0d 0a 50 6c 65 61 73 65 20 6e 6f 74 65 2c 20 77 ..Please note, w 36f0: 65 27 6c 6c 20 69 6e 76 6f 6b 65 20 74 68 65 20 e'll invoke the 3700: 3c 62 3e 41 73 45 57 4b 42 28 29 3c 2f 62 3e 20 <b>AsEWKB()</b> 3710: 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 69 6e 20 SQL function in 3720: 6f 72 64 65 72 20 74 6f 20 63 6f 6e 76 65 72 74 order to convert 3730: 20 61 6e 79 20 53 70 61 74 69 61 4c 69 74 65 27 any SpatiaLite' 3740: 73 20 6f 77 6e 20 3c 62 3e 42 4c 4f 42 3c 2f 62 s own <b>BLOB</b 3750: 3e 20 67 65 6f 6d 65 74 72 79 20 69 6e 74 6f 20 > geometry into 3760: 74 68 65 20 65 71 75 69 76 61 6c 65 6e 74 20 3c the equivalent < 3770: 62 3e 42 59 54 45 41 20 45 57 4b 42 3c 2f 62 3e b>BYTEA EWKB</b> 3780: 20 6e 6f 74 61 74 69 6f 6e 20 72 65 71 75 69 72 notation requir 3790: 65 64 20 62 79 20 50 6f 73 74 47 49 53 2e 3c 62 ed by PostGIS.<b 37a0: 72 3e 0d 0a 3c 74 61 62 6c 65 20 62 67 63 6f 6c r>..<table bgcol 37b0: 6f 72 3d 22 23 66 66 66 66 65 38 22 20 77 69 64 or="#ffffe8" wid 37c0: 74 68 3d 22 31 30 30 25 22 3e 0d 0a 3c 74 72 3e th="100%">..<tr> 37d0: 3c 74 64 20 61 6c 69 67 6e 3d 22 63 65 6e 74 65 <td align="cente 37e0: 72 22 3e 3c 62 3e 43 61 76 65 61 74 3a 20 41 73 r"><b>Caveat: As 37f0: 45 57 4b 42 28 29 3c 2f 62 3e 3c 2f 74 64 3e 3c EWKB()</b></td>< 3800: 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 3c 68 /tr>..<tr><td><h 3810: 72 3e 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 r></td></tr>..<t 3820: 72 3e 3c 74 64 3e 0d 0a 41 6e 79 20 70 72 65 76 r><td>..Any prev 3830: 69 6f 75 73 20 76 65 72 73 69 6f 6e 20 6f 66 20 ious version of 3840: 53 70 61 74 69 61 4c 69 74 65 20 28 74 68 69 73 SpatiaLite (this 3850: 20 69 6e 63 6c 75 64 69 6e 67 20 74 68 65 20 63 including the c 3860: 75 72 72 65 6e 74 20 3c 62 3e 34 2e 31 2e 31 3c urrent <b>4.1.1< 3870: 2f 62 3e 29 20 73 75 70 70 6f 72 74 65 64 20 61 /b>) supported a 3880: 20 62 75 67 67 69 73 68 20 3c 62 3e 41 73 45 57 buggish <b>AsEW 3890: 4b 42 28 29 3c 2f 62 3e 20 69 6d 70 6c 65 6d 65 KB()</b> impleme 38a0: 6e 74 61 74 69 6f 6e 20 63 6f 6d 70 6c 65 74 65 ntation complete 38b0: 6c 79 20 75 6e 61 62 6c 65 20 74 6f 20 63 72 65 ly unable to cre 38c0: 61 74 65 20 76 61 6c 69 64 20 45 57 4b 42 20 47 ate valid EWKB G 38d0: 65 6f 6d 65 74 72 69 65 73 20 74 6f 20 62 65 20 eometries to be 38e0: 70 61 73 73 65 64 20 74 6f 20 50 6f 73 74 47 49 passed to PostGI 38f0: 53 2e 0d 0a 49 20 70 72 65 73 75 6d 65 20 74 68 S...I presume th 3900: 61 74 20 6e 6f 62 6f 64 79 20 72 65 61 6c 6c 79 at nobody really 3910: 20 61 74 74 65 6d 70 74 65 64 20 74 6f 20 75 73 attempted to us 3920: 65 20 74 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 e this function 3930: 62 65 66 6f 72 65 2c 20 73 6f 20 74 68 69 73 20 before, so this 3940: 62 75 67 20 70 61 73 73 65 64 20 63 6f 6d 70 6c bug passed compl 3950: 65 74 65 6c 79 20 75 6e 6e 6f 74 69 63 65 64 20 etely unnoticed 3960: 73 69 6e 63 65 20 6e 6f 77 2e 3c 62 72 3e 0d 0a since now.<br>.. 3970: 55 73 69 6e 67 20 74 68 65 20 6c 61 74 65 73 74 Using the latest 3980: 20 76 65 72 73 69 6f 6e 20 6f 66 20 74 68 65 20 version of the 3990: 63 6f 64 65 20 61 76 61 69 6c 61 62 6c 65 20 66 code available f 39a0: 72 6f 6d 20 74 68 65 20 46 6f 73 73 69 6c 20 72 rom the Fossil r 39b0: 65 70 6f 73 69 74 6f 72 79 20 69 73 20 73 74 72 epository is str 39c0: 69 63 74 6c 79 20 72 65 71 75 69 72 65 64 20 73 ictly required s 39d0: 6f 20 74 6f 20 72 65 61 6c 6c 79 20 67 65 74 20 o to really get 39e0: 61 20 77 6f 72 6b 69 6e 67 20 41 73 45 57 4b 4b a working AsEWKK 39f0: 28 29 2e 0d 0a 3c 2f 74 64 3e 3c 2f 74 72 3e 0d ()...</td></tr>. 3a00: 0a 3c 2f 74 61 62 6c 65 3e 0d 0a 3c 62 72 3e 0d .</table>..<br>. 3a10: 0a 42 61 63 6b 20 74 6f 20 3c 62 3e 56 69 72 74 .Back to <b>Virt 3a20: 75 61 6c 50 47 3c 2f 62 3e 20 3c 61 20 68 72 65 ualPG</b> <a hre 3a30: 66 3d 22 68 74 74 70 73 3a 2f 2f 77 77 77 2e 67 f="https://www.g 3a40: 61 69 61 2d 67 69 73 2e 69 74 2f 66 6f 73 73 69 aia-gis.it/fossi 3a50: 6c 2f 76 69 72 74 75 61 6c 70 67 2f 69 6e 64 65 l/virtualpg/inde 3a60: 78 22 3e 68 6f 6d 65 20 70 61 67 65 3c 2f 61 3e x">home page</a> 3a70: 0a 5a 20 30 62 36 32 36 37 30 33 63 39 63 37 64 .Z 0b626703c9c7d 3a80: 61 66 64 31 62 62 62 31 37 33 36 30 62 38 65 33 afd1bbb17360b8e3 3a90: 34 66 30 0a 4f0.