1

Question:

Is there a way to use names instead of question marks for paramaterized queries? If so, can anyone suggest some material that explains how to do this/the syntax?

A bit more detail:

For example, if I have something like:

INSERT INTO inventory VALUES(?)

Is it possible to have something like this instead that does the exact same thing as the question mark:

INSERT INTO inventory VALUES("prices")

I tried checking to see if it would work myself before posting the question, but it didn't work. So, I thought I'd ask if it was possible.

I feel like if you have a really long query with, let's say 20 parameters, you don't want to have to count question marks to make sure you have enough parameters whenever you change something. Also, I think it might make the code a bit more readable (especially if you have a lot of parameters to keep track of).

I'm rather new to sql, so I am not sure if it makes much of a difference (for this question) if I add that I'm using postgresql.

Note:

There is a similar question here, but it didn't have an answer that was helpful

1
  • Can you please describe the context? What will evaluate the parametrized SQL statement? Which API are you considering? Commented Mar 2, 2016 at 2:35

1 Answer 1

0

I suggest to encapsulate the big query in a function, where you can use parameter names. One example (out of many):

You can even set default values and call the function with named parameters, etc.:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.