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

Categories

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 '#'


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

1 Answer

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...