Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7662345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:46:36+00:00 2026-05-31T13:46:36+00:00

My application uses a PostgreSQL 9.1 database. We’re in our beta phase and we

  • 0

My application uses a PostgreSQL 9.1 database. We’re in our beta phase and we occaisionally find bugs in our PostgreSQL schema. We’ve got an installer written and working, but now we’re at the point where there are installations out there that will need to be updated when we make our next release.

I posted an earlier question here asking how to get my script to make decisions. The answer I went with was to use the DO statement. This is working great, but I’ve run into a problem.

We’ve added a table to our database that keeps track of the last version that was installed. My script looks like this:

DO $$$
BEGIN
    IF NOT EXISTS ( SELECT * FROM "CarSystem"."CarSystem_Versions" WHERE "VersionId" = 2 ) THEN

        -- Schema update statements go here

    END IF;
END;
$$$ LANGUAGE plpgSQL;

Most of the statements are simple thngs like CREATE or DROP statements. But one of the things I have to do in this next release is apply a code change to a stored function. The function is also written in plpgSQL. I used three (3) $$$ symbols in the code above because this stored procedure uses two (2) $$ symbols, because I figured this would make the nested plpgSQL look different and not make the second set of dollar signs terminate the first.

Yet I’m getting an error when PostgreSQL hits the DECLARE statement in my stored procedure. It doesn’t see the text of the function as being quoted.

What is the correct way of dong this? Should I just put the stored procedure outside of this DO block and use a CREATE OR REPLACE statemnt to declare it? Or is there a way I can keep the code inside the condition?

Tony

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:46:38+00:00Added an answer on May 31, 2026 at 1:46 pm

    Try:

    DO $outer$
    BEGIN
        IF NOT EXISTS ( SELECT * FROM "CarSystem"."CarSystem_Versions" WHERE "VersionId" = 2 ) THEN
    
            -- Schema update statements go here
    
        END IF;
    END;
    $outer$ LANGUAGE plpgSQL;
    

    4.1.2.4. Dollar-quoted String Constants

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I installed an application that uses a PostgreSQL database. When I installed the application
I have a Spring application which uses Hibernate on a PostgreSQL database. I'm trying
I'm developing a multi-user application which uses a (postgresql-)database to store its data. I
I am thinking of working on a Rails application that uses PostgreSQL. I have
My application uses MS access database to save some sensitive information. Though that information
Our application uses SQL Server Reporting Services and allows users to add custom filters
Our application uses Hibernate with Sql Server 2005. Being a DBA, I am not
Our application uses a SQL Server back-end with many stored procedures. Recently, while trying
Application uses Entity Framework 4.1 with database first approach. I have in database a
Our application uses an animation to fade out a message window when it's closed.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.