473,624 Members | 2,234 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I do conditional 'drop table' in Postgres

if exists (select * from sysobjects where id =
object_id(N'[dbo].[pp_fisk]') and OBJECTPROPERTY( id, N'IsUserTable') = 1)
drop table [dbo].[pp_fisk]
GO

For instance, this is a valid script in Ms SQL, it will drop table
pp_fisk only if it exists, is there a way to do something similar in
Postgres? Tnx in advance.

Dragan


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 23 '05 #1
1 3566
Dragan Matic wrote:
if exists (select * from sysobjects where id =
object_id(N'[dbo].[pp_fisk]') and OBJECTPROPERTY( id, N'IsUserTable') = 1)
drop table [dbo].[pp_fisk]
GO

For instance, this is a valid script in Ms SQL, it will drop table
pp_fisk only if it exists, is there a way to do something similar in
Postgres? Tnx in advance.

Dragan


I'm working from memory here, so exact syntax might be incorrect.

perform select * from pg_table where ....;
if found then
drop table ...
end if

This applies to plpgsql only. Please pay attention, however, that if you
are going to be dropping and recreating tables from this function, you
must have all queries relating this table use "execute". Otherwise, the
table's OID is going to be cached the first time code referencing this
table (in "from") is run, and subsequent runs in the same session will
not find the table (even if you create a new table with the same name).
If that is a problem for you, consider replacing "drop table" with
"delete from table", which will delete all elements form the table, but
leave the table itself.

Shachar

--
Shachar Shemesh
Lingnu Open Source Consulting
http://www.lingnu.com/
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2011
by: Ilik | last post by:
Hi all I'm trying to create a summery table of rain data that holds a record for every 0.1mm of rain in the following format: Station Name, Time, Value A, 2002-12-03 14:44:41.000, 0.1 A, 2002-12-03 14:45:45.000, 0.1 A, 2002-12-03 14:49:45.000, 0.1 A, 2002-12-09 05:30:35.000, 0.1 A, 2002-12-09 05:30:37.000, 0.1
3
10965
by: David Link | last post by:
Hi All, Here's a Conditional drop_table func for those interested. There was a thread on this a long time back. We do this all the time : DELETE TABLE sales; CREATE TABLE sales (...);
2
8938
by: John Kreps | last post by:
(acc 2002) I've got six unbound text boxes on a subform that has a white background. Each of those six boxes has an expression that when true, will change its background from white to another color. These text boxes need to go behind a single line of other bound text boxes (which show the actual record). I.e., the purpose of the unbound text boxes w/conditional formatting is to highlight the record/background with one of six colors.
3
12084
by: B Love | last post by:
I would like to display a drop-down list on a form conditional on the value of another field on the same form. I am not sure if this is good form or not. I am using Access97, but have access to 2000 also. The specific scenario is this: I have 2 fields on a form. One is called "Manufacturer." The other is called "ProductLine." I would like to display specific product lines of the selected Manufacturer. Now, here's the bad news: my SQL and VB...
1
2452
by: Thomas Chille | last post by:
Hello! I have a Problem. A table with a ForeignKeyRef exits. The Name of the field with this FK-Constraint is 'id_employee' because it is referencing the field 'id_employee' in 'public.sd_employee'. I drop this column of the table with cascade in a script: ALTER TABLE public.sd_messaging_participant DROP COLUMN id_employee CASCADE;
1
1736
by: Ed L. | last post by:
I'm trying to unsuccessfully to drop a database using the latest CVS code for 8.0.0, getting the following error: ERROR: cannot drop the currently open database So I must have a connection open, right? So I look for connections with the command I use on 7.3.4 but see nothing: SELECT pg_stat_get_backend_pid(S.backendid) AS pid, db.datname AS database, dbu.usename AS user,
1
3362
by: David Parker | last post by:
I have a process that hangs doing a "drop schema cascade delete". This happens in a slonik command, which runs fine if I run it directly from the command line, but hangs if run from inside my process. I'm pretty sure I'm doing something silly and it's not a slony-specific thing, and I'm hoping that somebody can point me to a server debugging technique I can use to track this down. I'm using 7.4.5. My server, run with "-d 5", stops logging at...
3
3741
by: msrviking | last post by:
Hello everybody, After several attempts of writing the query, I had to post my requirement in the forum. Here is what I have, what I need and what I did. Table A Col1 Col2 1 Nm1
1
1869
by: colemanj4 | last post by:
Hello, I have a form with 2 drop downs. In the first drop down you choose a product and the second you choose the process step. Now as an example I have products A, B, C and D. Product A has steps 1, 2, 3, 4; B has 1, 3, 4; C has 2, 3, 4; and D has 1, 2, 4. I have a products table and a step table, but no links between them as of yet.
0
8177
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8681
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8341
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8488
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6112
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1793
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.