0

我知道 \d 仅适用于 psql,我可以使用 psql -E 查看用于实现 \d 的实际 SQL 查询是什么

这是我的例子

\d foo_table
********* QUERY **********
SELECT c.oid,
  n.nspname,
  c.relname
FROM pg_catalog.pg_class c
     LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relname ~ '^(foo_table)$'
  AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY 2, 3;
**************************

********* QUERY **********
SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, c.relhastriggers,        
c.relhasoids, '', c.reltablespace
FROM pg_catalog.pg_class c
 LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)
WHERE c.oid = '16386'

**************************

********* QUERY **********
SELECT a.attname,
  pg_catalog.format_type(a.atttypid, a.atttypmod),
  (SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128)
   FROM pg_catalog.pg_attrdef d
   WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef),
  a.attnotnull, a.attnum
FROM pg_catalog.pg_attribute a
WHERE a.attrelid = '16386' AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
**************************

********* QUERY **********
SELECT c.oid::pg_catalog.regclass FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i 
WHERE c.oid=i.inhparent AND i.inhrelid = '16386' ORDER BY inhseqno
**************************

有多个查询,其中一些以“;”结尾 有些不是。我完全糊涂了。我应该在 PHP 中使用什么查询来执行与“\d”相同的操作?


每个自定义帖子的 wordpress 侧边栏

我正在尝试让 wordpress 为自定义帖子类型的每个帖子添加一个侧边栏。因此,当我转到小部件区域时,我希望侧边栏的数量与我命名为投资组合的自定义帖子类型的帖子一样多。

这是我正在使用的代码,但我只得到 1 个没有标题的侧边栏。

更新:我在代码中添加了全局 $posts,现在我得到了侧边栏,然后我将 the_title() 更改为 get_the_title()。现在它正在工作。完整代码如下。如果有人有更好的解决方案,请告诉我。

function the_slug() {
    $post_data = get_post($post->ID, ARRAY_A);
    $slug = $post_data['post_name'];
    return $slug; 
}

add_action( 'init', 'portfolios_sidebars' );
/**
 * Create widgetized sidebars for each portfolio
 *
 * This function is attached to the 'init' action hook.
 */

function portfolios_sidebars() {
    $args = array( 'post_type' => 'portfolios', 'numberposts' => -1, 'post_status' => 'publish'); 
    $portfolios = get_posts( $args );
    global $post;
    if ($portfolios) {
        foreach ( $portfolios as $post ) {
            setup_postdata($post);
            $portfoliotitle = get_the_title();
            $portfolioslug = the_slug();
            register_sidebar( array(
                'name' => $portfoliotitle,
                'id' => $portfolioslug . '-sidebar',
                'description' => 'This is the ' . $portfoliotitle . ' widgetized area',
                'before_widget' => '<aside id="%1$s" class="widget %2$s" role="complementary">',
                'after_widget' => '</aside>',
                'before_title' => '<h4 class="widget-title">',
                'after_title' => '</h4>',
            ) );
        }
        wp_reset_postdata();
    }
}
4

1 回答 1

1

幸运的是,我找到了答案。 http://www.linuxscrew.com/2009/07/03/postgresql-show-tables-show-databases-show-columns/

于 2012-11-23T01:26:06.637 回答