Acep Muhamad Saepuloh
Acep Muhamad Saepuloh

Reputation: 161

How to Escape Semicolon in Sql

How to escape semicolon in Sql ? I used playframework i tried to insert html code inside "values" but when i try using semicolon it's not working ?

    CREATE TABLE "R_EMAIL_TEMPLATE"
    (
        "ID" uuid NOT NULL,
        "WP_ID" uuid NOT NULL,
        "CODE" text NOT NULL,
        "SUBJECT" text NOT NULL,
        "CONTENT" text NOT NULL,
        "CREATED_AT" timestamp without time zone,
        "CREATED_BY" text,
        "UPDATED_AT" timestamp without time zone,
        "UPDATED_BY" text,
        CONSTRAINT "R_EMAIL_TEMPLATE_pkey" PRIMARY KEY ("ID"),
        CONSTRAINT "R_EMAIL_TEMPLATE_WP_pkey" FOREIGN KEY ("WP_ID") REFERENCES "C_WP" ("ID")
    );
    INSERT INTO "R_EMAIL_TEMPLATE"
        VALUES (
            '30abd6ec-3496-45ff-be54-7f6f9290ebc4',
            '30abd6ec-3496-45ff-be54-7f6f9290ebcf',
            'user-activation',
            'User Registration',
            ';',
            '2018-05-17 19:02:39.643',
            'LOGIN',
            null,
            null
        );

Upvotes: 0

Views: 12429

Answers (2)

Vivek Pakmode
Vivek Pakmode

Reputation: 1026

Use \ to set escape character and try following:

INSERT INTO "R_EMAIL_TEMPLATE"
 VALUES (
    '30abd6ec-3496-45ff-be54-7f6f9290ebc4',
    '30abd6ec-3496-45ff-be54-7f6f9290ebcf',
    'user-activation',
    'User Registration',
    '\;',
    '2018-05-17 19:02:39.643',
    'LOGIN',
    null,
    null
);

Upvotes: 0

Vadim
Vadim

Reputation: 4120

Semicolon does not need to be escaped. It looks like problem is not about semicolon, but about double quotes you used in second INSERT

String values in SQL must be in single quotes. Double quote is reserved for object names such as schema/tables/columns names etc.

so try

INSERT INTO "R_EMAIL_TEMPLATE"
 VALUES (
    '30abd6ec-3496-45ff-be54-7f6f9290ebc4',
    '30abd6ec-3496-45ff-be54-7f6f9290ebcf',
    'user-activation',
    'User Registration',
    ';',
    '2018-05-17 19:02:39.643',
    'LOGIN',
    null,
    null
);

instead...

Upvotes: 2

Related Questions