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

  • SEARCH
  • Home
  • 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 6829343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:29:21+00:00 2026-05-26T22:29:21+00:00

Without functions, I can do: DELETE FROM table1 WHERE something=’hello’ And my rows with

  • 0

Without functions, I can do:

DELETE FROM table1
WHERE something='hello'

And my rows with the value of something=’hello’ get deleted, but as soon I implement functions, I begin to have problems with quotation marks.

CREATE OR REPLACE FUNCTION somefunc(varchar)
RETURNS varchar AS $$
BEGIN

  DELETE FROM table1
  WHERE something='$1';

  DELETE FROM table2
  WHERE something='$1';

  RETURN $1;

END;
$$ LANGUAGE plpgsql;`

Nothing seems to work. I have tried (all variations that I saw on SO or elsewhere):

something=$1   <-- says column "hello" doesn't exist (because no quotes are given)
something=''$1''
something='''$1'''
something=''''$1''''
something='''||$1||'''
something=$Q$$1$Q1$   <--- gives syntax error
something=$Q1$ $1 $Q1$
something=$$ $1 $$
something=quote_literal($1)

And many other variations. How do I get around this??

Btw, I am using a python script to run the function. Here’s the line that runs it. I’ve also tried adding quotes into this line as well to no avail:

cur.execute("SELECT somefunc(%s);" % (sys.argv[2]))

Thank you!

  • 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-26T22:29:22+00:00Added an answer on May 26, 2026 at 10:29 pm

    This behavior is based on the implicit use of prepare statements. When prepared statements are used, query and parameters are passed to the database server separately. Do not quote values in that scenario.
    PL/pgSQL uses prepared statements, psycopg2 uses prepared statements, too:

    ...
    DECLARE myvar int;
    BEGIN
       DELETE FROM mytab WHERE column = myvar; -- quietly using prepared statement
    

    versus

    DECLARE myvar int;
    BEGIN
       -- using dynamic SQL is similar to classic languages, quoting is necessary
       -- but use the quote_literal() function to protect against SQL injection
       EXECUTE 'DELETE FROM mytab WHERE column = ' || quote_literal(myvar);
    
       -- or dynamic SQL with "USING" clause 
       EXECUTE 'DELETE FROM mytab WHERE column = $1' USING myvar;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Some C functions can modify the string value without that I pass the address
How can you prematurely exit from a function without returning a value if it
Can a function return more than one value directly (i.e., without returning in parameters
How can i skip first argument without giving any value in function call,so that
How can i get variable in handler function of obj ? Without reference of
I am trying to delete an object from its parent object without success... When
How can I delete a node (between two nodes) from a single linked list
Help, I can't function without Resharper . All of a sudden my Alt +
How can I create a buffer in linux kernel without malloc() function (or calloc()
How can we implement the modulo operator as a function in C without using

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.