question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Name array type doesn't parse

See original GitHub issue

I’m doing reflection on my PostgreSQL database and I have this query:

select
  n.nspname as "schemaName",
  t.typname as "name",
  array(
    select
      e.enumlabel
    from
      pg_catalog.pg_enum as e
    where
      e.enumtypid = t.oid
  ) as "variants"
from
  pg_catalog.pg_type as t
  left join pg_catalog.pg_namespace as n on n.oid = t.typnamespace
where
  t.typtype = 'e';

Which has a sample result of:

 schemaName |    name    |     variants      
------------+------------+-------------------
 public     | bug_status | {new,open,closed}
 a          | letter     | {a,b,c,d}
 b          | color      | {red,green,blue}
(3 rows)

I’d expect the pg module to parse the variants column as an array of strings, but that’s not what happens. Instead the variants column is the string {a,b,c,d} for example.

After some digging the type appears to be named _name with an id of 1003, which is an array type for name with an oid of 19. For more information:

select typname, oid, typarray from pg_type where oid in (1003, 19);

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
calebmercommented, Apr 10, 2016

@vitaly-t not certain, but vehicle looks like a custom type, so vehicle[] probably wouldn’t (and couldn’t) be included in pg-types parsing.

1reaction
langpavelcommented, Apr 10, 2016

I agree. You can fix this by typecasting to text (I guess) in your nested query for now:

select e.enumlabel::text
from pg_catalog.pg_enum as e
where e.enumtypid = t.oid
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to parse C# generic type names? - Stack Overflow
Well, I had a lot of fun writing this little parsing class using Regex and named capture groups (?<Name>group) .
Read more >
Bug: Query string array parsing doesn't work properly on large ...
Describe the bug. I need to send an array of objects through query string to express-validator. To do so, I call the route...
Read more >
Error when trying to use output of Parse JSON
In your schema, it's assigning a type of "array" to one of the values. And that value is coming back in the results...
Read more >
SyntaxError: JSON.parse: bad parsing - JavaScript | MDN
JSON.parse() parses a string as JSON. This string has to be valid JSON and will throw this error if incorrect syntax was encountered....
Read more >
Documentation - Everyday Types - TypeScript
In this chapter, we'll cover some of the most common types of values you'll find in JavaScript code, and explain the corresponding ways...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found