Last active
August 9, 2016 06:59
-
-
Save TimJMartin/f03275413cc869ccba0a1710bf9aafb2 to your computer and use it in GitHub Desktop.
Some very useful PostgreSQL/PostGIS queries and functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The following is a set of useful PostGIS queries and functions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ALTER TABLE test1 ADD COLUMN id SERIAL PRIMARY KEY; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Login to psql and run the following | |
-- What is the result? | |
SELECT MAX(id) FROM your_table; | |
-- Then run... | |
-- This should be higher than the last result. | |
SELECT nextval('your_table_id_seq'); | |
-- If it's not higher... run this set the sequence last to your highest pid it. | |
-- (wise to run a quick pg_dump first...) | |
SELECT setval('your_table_id_seq', (SELECT MAX(id) FROM your_table)); | |
-- if your tables might have no rows | |
-- false means the set value will be returned by the next nextval() call | |
SELECT setval('your_table_id_seq', COALESCE((SELECT MAX(id)+1 FROM your_table), 1), false); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ALTER TABLE mytable | |
ALTER COLUMN geom | |
TYPE Geometry(Point, 32644) | |
USING ST_Transform(geom, 32644); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://blog.andyet.com/2015/04/06/postgres-pubsub-with-json/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment