Skip to content
Advertisement

Convert oid to json as int instead of string

Using Postgres 12, the following will return an int JSON representation:

Whereas if the type is oid, it will return it as string:

Since oid is inherently an int value, I would like it to be represented as such. I tried creating a cast between oid and both text and json types, but neither seems to be picked up by to_json.

Is there a way to make to_json represent an oid as an int, outside of casting each oid column to int explicitly?

Advertisement

Answer

You will have to use an explicit cast, because it is hard-coded that PostgreSQL treats oid as a string.

You could suggest the following patch to the pgsql-hackers mailing list:

That would change the behavior, and I don’t see why the patch shouldn’t be accepted.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement