Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- DB_NAME='postgres'
- USER='postgres'
- BATCH_SIZE=10 # Only fetch 10 records for testing
- OUTPUT_DIR='/home/ec2-user/data'
- CONTAINER_NAME='postgresql' # Your actual PostgreSQL container name
- # Ensure the output directory exists
- mkdir -p $OUTPUT_DIR
- # Output file path
- HOST_OUTPUT_FILE="${OUTPUT_DIR}/test_geocoded_data.geojson"
- # Run query for only 10 records
- docker exec -i $CONTAINER_NAME psql -U $USER -d $DB_NAME -t -A -c "
- SELECT jsonb_pretty(jsonb_build_object(
- 'type', 'FeatureCollection',
- 'features', COALESCE(
- jsonb_agg(
- jsonb_build_object(
- 'type', 'Feature',
- 'geometry', ST_AsGeoJSON(geom)::jsonb,
- 'properties', jsonb_build_object(
- 'owner_last_name', owner_last_name,
- 'owner_first_name', owner_first_name,
- 'owner_city', owner_city,
- 'owner_state', owner_state,
- 'owner_zip', owner_zip,
- 'amount', amount,
- 'holder_name', holder_name,
- 'po_box', po_box
- )
- )
- ), '[]'::jsonb -- Correct placement of closing parentheses
- )
- ))
- FROM (
- SELECT geom, owner_last_name, owner_first_name, owner_city, owner_state, owner_zip, amount, holder_name, po_box
- FROM unclaimed_property
- WHERE geom IS NOT NULL
- LIMIT $BATCH_SIZE
- ) t" > $HOST_OUTPUT_FILE
- echo "Exported 10 records to $HOST_OUTPUT_FILE"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement