2

As I found in documentation:

Parenthesized type modifiers (e.g., the precision field for type numeric) are discarded by CREATE FUNCTION

Are there any alternatives to return varchar(N) type from plpgsql function?


question update:

On picture you can see that Name column recognised as varchar(128), however Number column is recognised as nonsized varchar

Result example

f_concat function returns: cast(res as varchar(255));

4
  • Why do you think you need that? What problem are you trying to solve? Commented Nov 11, 2016 at 13:52
  • @a_horse_with_no_name One old Delphi program see everything without length as TEXT BLOB. So if I select fields from varchar(255) column it shows correctly as varchar(255), but if I use function on that column result then result is character varying even if I make cast as varchar(255) inside the function. Commented Nov 11, 2016 at 15:46
  • 1
    I think the only way is a view which does an explicit cast to varchar(x) Commented Nov 11, 2016 at 16:30
  • @Ice2burn: We have an old Delphi program with exactly this problem, and we use domains as a workaround Commented Nov 11, 2016 at 21:37

1 Answer 1

4

You can preserve the type modifier for a function result by creating a domain. Postgres will use the underlying varchar(N) type when sending column descriptions to your client:

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.