What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

Is there a way to ask for the columns info using the `Propel::getConnection()` ?

Chemaclass
Chemaclass Tech Lead Spryker Solution Partner Posts: 213 🧑🏻‍🚀 - Cadet
edited June 2023 in Help

Is there a way to ask for the columns info using the Propel::getConnection() ?
I tried exec('\d+ table_name'); but it’s not working (it says syntax error).
I tried also using this query, but the output is not the columns but metadata that I am not really interested…

SELECT *
FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name = 'table_name';

I would like to get the column names from a given table in a specific schema using a Propel connection. Does anyone has other ideas or if this is possible? 🤔

Thanks in advance!

Tagged:

Best Answer

  • Alberto Reyer
    Alberto Reyer Posts: 690 🪐 - Explorer
    Answer ✓

    Propel uses PDO under the hood and \d is a command specific to the DB engine and therefore not supported by PDO.

    The column names can be retrieved like (maybe you have overseen them with all the meta data returned by your query):

    SELECT COLUMN_NAME
    FROM information_schema.columns
    WHERE table_schema = 'public'
      AND table_name = '<table_name>';
    

Answers

  • Alberto Reyer
    Alberto Reyer Posts: 690 🪐 - Explorer
    Answer ✓

    Propel uses PDO under the hood and \d is a command specific to the DB engine and therefore not supported by PDO.

    The column names can be retrieved like (maybe you have overseen them with all the meta data returned by your query):

    SELECT COLUMN_NAME
    FROM information_schema.columns
    WHERE table_schema = 'public'
      AND table_name = '<table_name>';
    
  • Chemaclass
    Chemaclass Tech Lead Spryker Solution Partner Posts: 213 🧑🏻‍🚀 - Cadet

    oh gosh, you’re totally right!
    I need to SELECT COLUMN_NAME of course!
    Thank you @UL6DGRULR 🙇🏼