Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
734 views
in Technique[技术] by (71.8m points)

stored procedures - postgresql replace symbol for store function variable?

I find '#' can replace some string in posgresql like:

SELECT
    'Record #' || i
FROM
    generate_series(1, 1000) i;

The symbol '#' can replace the by i, in this SQL commands.

I want to do similar like this for function like

SELECT lo_unlink('#') || i  
From
    SELECT picture i FROM image where belong_to = 254;

Of course '#' there is grammar error around '#', I just want to know any placehold grammar or symbol can work in function parameter like it replace string mark '#'


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The symbol # is not replaced, you are concatenating a number to a string containing this symbol.

This concatenation can occur anywhere, including when building a function parameter:

SELECT lo_unlink('#' || i)
From
    SELECT picture i FROM image where belong_to = 254;

which, if i is number 1, will create (and call) lo_unlink('#1')

so you may want to use i directly:

SELECT lo_unlink(i)
From
    SELECT picture i FROM image where belong_to = 254;

which, if i is number 1, will create (and call) lo_unlink(1)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...