Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
718 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 Answer

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...