473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Exporting tables from Postgres to SQL

Hi,

How can I export some tables from Postgres to SQL scripts? I've tried the COPY...TO command but it's not really what I was looking for as it creates CSV files.

Cheers,

Matt
May 22 '07 #1
7 5070
michaelb
534 Expert 512MB
It does not have to be a CSV, the COPY command allows you to specify any delimiter you want.

I'm not sure though what you mean by "copy to SQL scripts"
It may help if you elaborate on what output format you're trying to create, and how you intend to use it.
May 22 '07 #2
I'm trying to get a .sql output, which in turn I want to convert to a shapefile (.shp).
May 22 '07 #3
michaelb
534 Expert 512MB
I'm trying to get a .sql output, which in turn I want to convert to a shapefile (.shp).
Sorry, but this does not tell me anything.
.sql is just an extension, which does not necessarily imply any specific standard or format, it only suggests that this file probably contains sql commands.

What you really need is to identify the exact format of what you call an .sql file.
May 22 '07 #4
Sorry for being a bit vague, I hadn't realised there were various types of SQL files. I checked the files and they're 'Microsoft server SQL query files'- does that help? Below I've copied a the text from the header and footer of a file similar to what I'd like to output.

Thanks
Expand|Select|Wrap|Line Numbers
  1. BEGIN;
  2. CREATE TABLE "txt_barrio" (gid serial PRIMARY KEY,
  3. "nombre" varchar(254),
  4. "izena" varchar(254),
  5. "text_angle" float8,
  6. "text_size" float8,
  7. "textstring" varchar(254));
  8. SELECT AddGeometryColumn('','txt_barrio','the_geom','23030','POINT',2);
  9. INSERT INTO "txt_barrio" ("nombre","izena","text_angle","text_size","textstring",the_geom) VALUES ('Poligono Industrial  La Coba','La Coba industrialdea','0.000000','31.123845','La Coba industrialdea / Poligono Industrial  La Coba','SRID=23030;0101000000316948FDC0F01E415D47207DAC095241');
  10. ..... 
  11. .....;
  12. END;
  13.  
May 23 '07 #5
michaelb
534 Expert 512MB
Thanks for clarification.
You need to look at pg_dump utility.
Give it a try, make sure to use the desired command line parameters.
I assume you want to dump data in a plain text format and probably want to use INSERT instead of COPY.
May 24 '07 #6
Thanks for the link. Although I managed to solve the problem just before going to lunch. A friend passed me a BAT file called postgistoshp.bat, which works, although I'm not sure how(!).

This is the code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. rem %1 database - %2 table
  3. pgsql2shp.exe -h <server_name> -u postgres <DB_name> <table_name>
  4.  
Cheers,

Matt
May 24 '07 #7
michaelb
534 Expert 512MB
Matt, thanks for the update.

I think pgsql2shp.exe comes with PostGIS Spatial Extensions package, something I wasn't aware of until now...

http://www.bostongis.com/PrinterFrie...=postgis_tut01
May 24 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: sridevi | last post by:
Hello How to export data from ms-access database to excel worksheet using ASP. mainly i need to export data to multiple worksheets. it is very urgent to us. i have a sample code which works...
30
by: btober | last post by:
Whenever I create a temporary table, with something like CREATE TEMPORARY TABLE temptable1 AS SELECT * FROM paid.ad_hoc_query; New schemas appear, with names like "pg_temp_1". I guess the...
1
by: Martin_Hurst | last post by:
Is it possible to establish a connection from within a postgres database to another external database on the network, i.e., not a java or scripting connection, BUT by some type of table definition...
4
by: Ati Rosselet | last post by:
I have several tables with common FKs.. the problem occurs when performing a large number of inserts on any of the tables at the same time. The first to start inserting seems to get a lock on the...
12
by: Jared Carr | last post by:
First I wish I knew how this was caused but here is our problem. Sometime in the recent past we got a duplicate table. Here is the result of a pg_dump with a pg_restore for just that table. ...
6
by: pgmoscatt | last post by:
I have just moved over to PostGres after using MySQL. In MySQL I could issue the command SHOW TABLES within a database to show what tables are within. I tried to do this with PostGres and I...
5
by: Prabu Subroto | last post by:
Dear my friends... I am using SuSE Linux 9.1 and postgres. I am a beginner in postgres, usually I use MySQL. I have 3 tables : appointment, appointment0 and appointment1. the fields of...
2
by: Snozz | last post by:
The short of it: If you needed to import a CSV file of a certain structure on a regular basis(say 32 csv files, each to one a table in 32 databases), what would be your first instinct on how to...
2
by: jjwiet | last post by:
Hello, I use access 2003 and attempting to export/copy records between two access databases (almost identical) with multiple tables (both databases having the same relations between the tables)....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.