On Sunday, April 26, 2020 at 7:10:18 PM UTC-7, BeeRich33 wrote:
>
> I am trying to look into the information_schema.columns table but I can't 
> seem to find it using the normal connector:
>
> DBHR = Sequel.connect('postgres://rich@localhost:5432/rich')
> fieldnames = DBHR[:columns].where(table_name: 'airports_gps').get(:
> column_name)
>
> This is what I'm trying to achieve:
>
> select column_name from information_schema.columns where table_name = 
> 'airports';
>
> I'm not sure how to get into that database and table.  *psql* is fine 
> with the query, as is another client application. 
>
> I also found this:  *PostgreSQL now uses the pg_* system catalogs instead 
> of the INFORMATION schema.*
>
> I'm just trying to get fieldnames from a table, and I'm thinking there's a 
> more direct way than abstracting to a *DB.do <<*...
>
> Any insight appreciated.  Cheers
>

The information_schema schema is not in the default PostgreSQL search 
path.  You need to use a qualified identifier, just as you are using in SQL:

  fieldnames = 
DBHR[Sequel[:information_schema][:columns]].where(table_name: 
'airports_gps').get(:column_name)

Note that you would actually want to do this, considering you can do:

  DBHR[:airports_gps].columns

In addition to being simpler and easier to read, it's also more accurate.  
If you have the airports_gps table in multiple schemas in the database, 
your long way is going to be incorrect.

BTW, in your SQL you are using airports as the table name, and in the 
Sequel code you are using airports_gps.  You probably want to double check 
what table name you want to use.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/bcda6a73-97cc-4f42-ae9f-3f4f97b806e4%40googlegroups.com.

Reply via email to