..or..
SELECT @some_variable = constraint_name FROM information_schema.table_c
IF @some_variable IS NOT NULL
begin
'do your stuff here
end
Main Topics
Browse All TopicsPostgreSQL question...
I want something like this:
CASE WHEN EXISTS(SELECT constraint_name FROM information_schema.table_c
ALTER TABLE "ProductPurchased" DROP CONSTRAINT "FK_ProductPurchased_Custo
END;
But that's not valid SQL.
Do you know a way to do that with valid PostgreSQL SQL?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi,
You can try this:
First create function:
CREATE OR REPLACE FUNCTION execute(in_sql TEXT) RETURNS void as $_$
BEGIN
EXECUTE in_sql;
RETURN;
END;
$_$ LANGUAGE plpgsql;
then you can do this:
select execute ('ALTER TABLE "ProductPurchased" DROP CONSTRAINT "FK_ProductPurchased_Custo
where exists (
SELECT constraint_name FROM information_schema.table_c
HTH
Dominik
Business Accounts
Answer for Membership
by: jimhornPosted on 2007-02-25 at 12:43:12ID: 18606056
In SQL you cannot use CASE as a decicion loop, such as...
onstraints WHERE constraint_name = 'FK_ProductPurchased_Custo mer') mer"
IF (some criteria) THEN
'do this
else
'do that
end if
Instead, use the SQL IF construct (no THEN or END IF required, but good to surround commands with begin..end)
IF EXISTS(SELECT constraint_name FROM information_schema.table_c
begin
ALTER TABLE "ProductPurchased" DROP CONSTRAINT "FK_ProductPurchased_Custo
end