473,405 Members | 2,379 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,405 software developers and data experts.

Problem in executing sql file

Hi all,
I am tring to execute sql scipts written in a seprate .sql file. In the begining i drop all the tables and create the new one. But while working with a completly new database there wont be any tabel to drop, so my drop query fails. Because of which furthor sql statements does not execute.So my table creation fails.I wants to execuet create statements even if drop statements fails. this sql files works fine on other databases. problem is only with the postgres.

regards
kunal
Oct 30 '07 #1
1 4211
rski
700 Expert 512MB
Hi all,
I am tring to execute sql scipts written in a seprate .sql file. In the begining i drop all the tables and create the new one. But while working with a completly new database there wont be any tabel to drop, so my drop query fails. Because of which furthor sql statements does not execute.So my table creation fails.I wants to execuet create statements even if drop statements fails. this sql files works fine on other databases. problem is only with the postgres.

regards
kunal
You can prepare the drop statement to behave as drop table if exists.
define a function

CREATE FUNCTION exec(TEXT) RETURNS VOID AS'
DECLARE
BEGIN
EXECUTE $1;
END;
LANGUAGE plpgsql;

and do
SELECT exec('DROP TABLE yourtable') WHERE EXISTS(SELECT * FROM pg_table WHERE tablename='yourtable');
Oct 30 '07 #2

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

Similar topics

0
by: burn_hall | last post by:
Hi, I have a problem and can't figure it out and need your help, please look at the following code and the output also a xml file snippet is down there too. Looking at the output I don't know why...
1
by: Tanuki | last post by:
Hi: I have a problem regarding filenames in Visual C++. I would like to read from files using relative filenames instead of absolute filenames. I have tried using the following fname =...
2
by: Joseph Geretz | last post by:
I'm having a credentialing problem in my web application. Actually, I don't think this is an IIS security issue, since I'm able to access the page I'm requesting. However, the executing page itself...
1
by: svijay | last post by:
hi I have got a strange problem. May I know any solution for this. Here is the detailed description about the problem We have got a mainframe system and also production and development...
7
by: David R. | last post by:
Hello all, I would like to generate a Sql-Script-File and a Batch-File to execute the Batch-File over C#-Code and use the SQL-File as an Input-File for the command "osql" in the Batch-File. I...
102
by: hug | last post by:
www.webmaster, was suggested that this ng could be a better place.] I've updated my test server to handle if-modified-since. I've noticed that the (old copies I run of) IE and Netscape seem...
3
by: ^MisterJingo^ | last post by:
Hi all, I've got a very small app which I want to read an xml config file which is stored in the directory of the exe. To do this I am using the following line of code: XmlTextReader reader =...
1
by: Manish | last post by:
Hi friends, Iam new to this group. I have problem with executing the output(exe) file in an another system. I have created and compiled in a VS 2005 tool. when i run the exe file in a new system....
1
by: Manish | last post by:
Hi friends, Iam new to this group. I have problem with executing the output(exe) file in a new system. I have created and compiled in a VS 2005 tool. when i run the exe file in a new system. its...
19
by: foolsmart2005 | last post by:
I have written a snake game. There are 2 levels in the game(I finished 1st level). It can run in VC++ without problem but, when I run it on the dev C++ 4.9.9.2, it cannot run. I want to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.